Proooof commited on
Commit
df657b3
·
verified ·
1 Parent(s): 9114194

Create inference_examples.py

Browse files
Files changed (1) hide show
  1. inference_examples.py +15 -0
inference_examples.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline, AutoTokenizer, AutoModelForTokenClassification
2
+
3
+ def demo_sentiment():
4
+ clf = pipeline("sentiment-analysis", model="YOUR-USERNAME/Finance-NLP-Toolkit")
5
+ print(clf("Shares plunged after the weak revenue outlook."))
6
+
7
+ def demo_ner():
8
+ tok = AutoTokenizer.from_pretrained("YOUR-USERNAME/Finance-NLP-Toolkit", revision="ner")
9
+ ner_model = AutoModelForTokenClassification.from_pretrained("YOUR-USERNAME/Finance-NLP-Toolkit", revision="ner")
10
+ ner = pipeline("token-classification", model=ner_model, tokenizer=tok, aggregation_strategy="simple")
11
+ print(ner("Microsoft will acquire Nuance for $19.7 billion in 2025."))
12
+
13
+ if __name__ == "__main__":
14
+ demo_sentiment()
15
+ demo_ner()