Views
No views yet

1# pip install accelerate
2from transformers import T5Tokenizer, T5ForConditionalGeneration
3
4tokenizer = T5Tokenizer.from_pretrained("knowledgator/flan-t5-base-for-classification")
5model = T5ForConditionalGeneration.from_pretrained("knowledgator/flan-t5-base-for-classification", device_map="auto")
6
7input_text = "Define sentiment of the following text: I love to travel and someday I will see the world."
8input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
9
10outputs = model.generate(input_ids)
11print(tokenizer.decode(outputs[0]))1# pip install unlimited-classifier
2
3from unlimited_classifier import TextClassifier
4
5classifier = TextClassifier(
6 labels=[
7 'positive',
8 'negative',
9 'neutral'
10 ],
11 model='knowledgator/flan-t5-base-for-classification',
12 tokenizer='knowledgator/flan-t5-base-for-classification',
13)
14output = classifier.invoke(input_text)
15print(output)