Create inference_examples.py
Browse files- 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()
|