LuxyR commited on
Commit
6fee902
·
verified ·
1 Parent(s): 2fd07c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -40,22 +40,29 @@ def classifier_2_predict(text):
40
  return result
41
 
42
  # ------------------------------
43
- # Árbitro decide qual IA acertou e explica
44
  # ------------------------------
45
  def judge_sentiment(text, result_1, result_2):
46
  prompt = (
47
  f"Sentence: \"{text}\"\n"
48
  f"Model A prediction: {result_1} (uses labels: negative, neutral, positive)\n"
49
  f"Model B prediction: {result_2} (uses labels: neg, neu, pos)\n\n"
50
- "Interpret the sentiment expressed in the sentence and judge whether each prediction is good or bad.\n"
51
- "The labels correspond to each other (e.g., 'positive' = 'pos').\n\n"
52
- "Then explain briefly why each model was judged good or bad.\n\n"
53
- "Respond ONLY in this exact format:\n"
 
 
 
54
  "Model A: good | Model B: bad\n"
 
 
 
 
55
  "Explanation: [your reasoning here]"
56
  )
57
- output = arbitro(prompt, max_new_tokens=100)[0]['generated_text'].strip()
58
- return f"Model A: {result_1} | Model B: {result_2}\n🤖 Árbitro: {output}"
59
 
60
  # ------------------------------
61
  # Pipeline principal
@@ -73,11 +80,12 @@ iface = gr.Interface(
73
  title="AI Sentiment Duel: Classificador de Sentimentos",
74
  description=(
75
  "Compare duas IAs na tarefa de identificar o sentimento de uma frase. "
76
- "Uma terceira IA, chamada **árbitro**, decide qual das respostas está mais correta e agora também **explica o porquê**.\n\n"
77
- "**Como funciona o julgamento do árbitro:**\n"
78
- "O árbitro usa o modelo **Flan-T5-Large** para interpretar o sentimento real da frase e avaliar se as classificações dos modelos A e B estão corretas.\n\n"
79
- "**Novo recurso:** o árbitro agora também mostra a lógica por trás de sua decisão — para fins de transparência e auditabilidade.\n\n"
80
- "⚠️ Ambos os modelos funcionam melhor com frases em inglês.\n\n"
 
81
  "💡 Exemplos:\n"
82
  "- 'I absolutely loved the movie!'\n"
83
  "- 'Not bad, but could be better.'"
 
40
  return result
41
 
42
  # ------------------------------
43
+ # Árbitro decide qual IA acertou e mostra os pesos
44
  # ------------------------------
45
  def judge_sentiment(text, result_1, result_2):
46
  prompt = (
47
  f"Sentence: \"{text}\"\n"
48
  f"Model A prediction: {result_1} (uses labels: negative, neutral, positive)\n"
49
  f"Model B prediction: {result_2} (uses labels: neg, neu, pos)\n\n"
50
+ "Interpret the real sentiment expressed in the sentence.\n"
51
+ "Judge whether each prediction is good or bad, and explain the parameters (weights) that influenced your decision.\n\n"
52
+ "Your judgment criteria (weights from 0 to 1):\n"
53
+ "- Semantic match (meaning alignment with the sentence)\n"
54
+ "- Tone match (emotional consistency)\n"
55
+ - Label accuracy (correct label among known sentiment labels)\n\n"
56
+ "Respond ONLY in this format:\n"
57
  "Model A: good | Model B: bad\n"
58
+ "Weights used:\n"
59
+ "- Semantic match: 0.4\n"
60
+ "- Tone match: 0.4\n"
61
+ "- Label accuracy: 0.2\n"
62
  "Explanation: [your reasoning here]"
63
  )
64
+ output = arbitro(prompt, max_new_tokens=150)[0]['generated_text'].strip()
65
+ return f"Model A: {result_1} | Model B: {result_2}\n🤖 Árbitro:\n{output}"
66
 
67
  # ------------------------------
68
  # Pipeline principal
 
80
  title="AI Sentiment Duel: Classificador de Sentimentos",
81
  description=(
82
  "Compare duas IAs na tarefa de identificar o sentimento de uma frase. "
83
+ "Uma terceira IA, chamada **árbitro**, decide qual resposta está mais correta e agora **explica os critérios (pesos) usados para julgar**.\n\n"
84
+ "**Critérios de julgamento do árbitro:**\n"
85
+ "- **Semantic match**: o quanto a resposta combina com o significado geral da frase.\n"
86
+ "- **Tone match**: o quanto a resposta combina com o tom emocional.\n"
87
+ "- **Label accuracy**: se o rótulo está entre os mais apropriados.\n\n"
88
+ "⚠️ Melhores resultados com frases em inglês.\n\n"
89
  "💡 Exemplos:\n"
90
  "- 'I absolutely loved the movie!'\n"
91
  "- 'Not bad, but could be better.'"