Views
No views yet
1import torch
2from transformers import pipeline
3"
4pipe = pipeline(
5 "text-generation",
6 model=model_id,
7 torch_dtype=torch.bfloat16,
8 device_map="auto",
9)
10messages = [
11 {"role": "user", "content": "\n\nYou are an expert text classifier. You need to classify the text below into one of the given classes. \n\nText:\n\nThe anticipation of the meteor shower has filled the astronomy club with an infectious excitement, as we prepare our telescopes for what could be a once-in-a-lifetime celestial event.\n\nClasses:\n\nAffirmative Sentiment;Mildly Affirmative Sentiment;Exuberant Endorsement;Objective Assessment;Critical Sentiment;Subdued Negative Sentiment;Intense Negative Sentiment;Ambivalent Sentiment;Sarcastic Sentiment;Ironical Sentiment;Apathetic Sentiment;Elation/Exhilaration Sentiment;Credibility Endorsement;Apprehension/Anxiety;Unexpected Positive Outcome;Melancholic Sentiment;Aversive Repulsion;Indignant Discontent;Expectant Enthusiasm;Affectionate Appreciation;Anticipatory Positivity;Expectation of Negative Outcome;Nuanced Sentiment Complexity\n\nThe output format must be:\n\nFinal class: {selected_class}\n\n"},
12]
13outputs = pipe(
14 messages,
15 max_new_tokens=256,
16)
17print(outputs[0]["generated_text"][-1])