straightline777 commited on
Commit
4a010be
·
verified ·
1 Parent(s): c6e8b16

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -28,24 +28,21 @@ def analyze_sentiment(text):
28
 
29
  def analyze_ner(text):
30
  predictions = clf_ner(text)
 
31
 
32
- keys = []
33
- values = []
34
- for i, label in enumerate(label_list):
35
- keys.append(f'LABEL_{i}')
36
- values.append(label)
37
-
38
- label_mapping = {k: v for (k, v) in zip(keys, values)}
39
 
40
  results = []
41
  for pred in predictions:
42
- results.append(
43
- f"Word: {pred['word']}\n"
44
- f"Predicted Tag: {label_mapping[pred['entity']]}\n"
45
- f"Confidence Probability: {pred['score']:.2f}\n"
46
- )
47
 
48
  return "\n".join(results)
 
49
  def analyze_text(text):
50
  sentiment_result = analyze_sentiment(text)
51
  ner_result = analyze_ner(text)
 
28
 
29
  def analyze_ner(text):
30
  predictions = clf_ner(text)
31
+ print(predictions) # Debugging statement to see the structure of the output
32
 
33
+ # Create label mapping from id2label
34
+ label_mapping = {f'LABEL_{i}': label for i, label in enumerate(label_list)}
35
+ print(label_mapping) # Debugging statement to see the label mapping
 
 
 
 
36
 
37
  results = []
38
  for pred in predictions:
39
+ word = pred['word']
40
+ tag = label_mapping[pred['entity']]
41
+ confidence = pred['score']
42
+ results.append(f"Word: {word}\nPredicted Tag: {tag}\nConfidence Probability: {confidence:.2f}\n")
 
43
 
44
  return "\n".join(results)
45
+
46
  def analyze_text(text):
47
  sentiment_result = analyze_sentiment(text)
48
  ner_result = analyze_ner(text)