49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
from transformers import AutoTokenizer, AutoModelForTokenClassification, TokenClassificationPipeline
|
|
from transformers import AutoModelForSequenceClassification, TextClassificationPipeline
|
|
import datetime
|
|
|
|
def printNow():
|
|
print(datetime.datetime.now())
|
|
|
|
def answer(prompt):
|
|
|
|
res = classifier(prompt)
|
|
print(res)
|
|
|
|
|
|
|
|
print('loading...')
|
|
|
|
|
|
def init_Intent():
|
|
model_name = 'qanastek/XLMRoberta-Alexa-Intents-Classification'
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
|
classifier = TextClassificationPipeline(model=model, tokenizer=tokenizer)
|
|
return classifier
|
|
|
|
def init_token_classification():
|
|
tokenizer = AutoTokenizer.from_pretrained('qanastek/XLMRoberta-Alexa-Intents-NER-NLU')
|
|
model = AutoModelForTokenClassification.from_pretrained('qanastek/XLMRoberta-Alexa-Intents-NER-NLU')
|
|
predict = TokenClassificationPipeline(model=model, tokenizer=tokenizer)
|
|
return predict
|
|
|
|
get_entities = init_token_classification()
|
|
get_intent = init_Intent()
|
|
|
|
|
|
|
|
|
|
sentence = ''
|
|
while sentence != 'exit':
|
|
printNow()
|
|
sentence = input("oui ?")
|
|
print(get_intent(sentence))
|
|
print(get_entities(sentence))
|
|
printNow()
|
|
|
|
|
|
|
|
|
|
|