Update app.py
Browse files
app.py
CHANGED
@@ -111,25 +111,17 @@ def extract_hashtags(text):
|
|
111 |
# -------------------------------------------------------------------
|
112 |
|
113 |
def get_frame_category_mapping(text):
|
114 |
-
"""
|
115 |
-
For each frame defined in frame_categories, this function uses a zero-shot classification
|
116 |
-
approach to assess qualitatively how strongly the text discusses the frame.
|
117 |
-
It builds a batched list of hypothesis templates and returns a mapping from frame to the best label.
|
118 |
-
"""
|
119 |
frames = list(frame_categories.keys())
|
120 |
-
# Build hypothesis templates—one per frame:
|
121 |
-
hypothesis_templates = [f"This text is {{}} about {frame}." for frame in frames]
|
122 |
-
# Repeat the same input text for each frame in the batch.
|
123 |
-
texts = [text] * len(frames)
|
124 |
-
# Batch call: each element of the batch uses its own hypothesis_template.
|
125 |
-
results = classifier(
|
126 |
-
texts,
|
127 |
-
candidate_labels=candidate_labels,
|
128 |
-
hypothesis_template=hypothesis_templates,
|
129 |
-
batch_size=len(frames) # process all at once
|
130 |
-
)
|
131 |
mapping = {}
|
132 |
-
for frame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
mapping[frame] = result["labels"][0]
|
134 |
return mapping
|
135 |
|
|
|
111 |
# -------------------------------------------------------------------
|
112 |
|
113 |
def get_frame_category_mapping(text):
|
|
|
|
|
|
|
|
|
|
|
114 |
frames = list(frame_categories.keys())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
mapping = {}
|
116 |
+
for frame in frames:
|
117 |
+
# Create a hypothesis template for this frame
|
118 |
+
hypothesis_template = f"This text is {{}} about {frame}."
|
119 |
+
# Run classifier for the given text and hypothesis_template
|
120 |
+
result = classifier(
|
121 |
+
text,
|
122 |
+
candidate_labels=candidate_labels,
|
123 |
+
hypothesis_template=hypothesis_template
|
124 |
+
)
|
125 |
mapping[frame] = result["labels"][0]
|
126 |
return mapping
|
127 |
|