Spaces:
Build error
Build error
Commit ·
1a4dad2
1
Parent(s): ca2c3c4
return top 3 predictions
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import re
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 4 |
|
|
@@ -10,8 +11,9 @@ def tag_job_description(job_description):
|
|
| 10 |
job_description = re.sub(r'[^a-zA-Z]', ' ', job_description)
|
| 11 |
inputs = tokenizer(job_description, truncation=True, max_length=512, return_tensors="pt")
|
| 12 |
outputs = model(**inputs)
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
demo = gr.Interface(fn=tag_job_description, inputs="text", outputs="text")
|
|
|
|
| 1 |
import re
|
| 2 |
+
import torch
|
| 3 |
import gradio as gr
|
| 4 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 5 |
|
|
|
|
| 11 |
job_description = re.sub(r'[^a-zA-Z]', ' ', job_description)
|
| 12 |
inputs = tokenizer(job_description, truncation=True, max_length=512, return_tensors="pt")
|
| 13 |
outputs = model(**inputs)
|
| 14 |
+
topk_values, topk_indices = torch.topk(outputs.logits, 3)
|
| 15 |
+
predicted_tags = [model.config.id2label[i] for i in topk_indices[0]]
|
| 16 |
+
return predicted_tags
|
| 17 |
|
| 18 |
|
| 19 |
demo = gr.Interface(fn=tag_job_description, inputs="text", outputs="text")
|