Upload 2 files
Browse files
intent.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, TextClassificationPipeline
|
4 |
+
|
5 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
6 |
+
|
7 |
+
model_name = 'qanastek/XLMRoberta-Alexa-Intents-Classification'
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
+
intent_classifier = TextClassificationPipeline(model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
+
|
13 |
+
def perform_intent_classification(text):
|
14 |
+
result = intent_classifier(text)
|
15 |
+
return {"Intent": [result]}
|
ner.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import torch
|
3 |
+
|
4 |
+
ner_model = pipeline('ner')
|
5 |
+
|
6 |
+
model_checkpoint = "huggingface-course/bert-finetuned-ner"
|
7 |
+
classifier = pipeline("token-classification", model=model_checkpoint, aggregation_strategy="simple")
|
8 |
+
|
9 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
10 |
+
|
11 |
+
def perform_ner(text):
|
12 |
+
# Your NER function implementation goes here
|
13 |
+
# Replace this with your own checkpoint
|
14 |
+
result = classifier(text)
|
15 |
+
return {"entities": [result]}
|