| from transformers import pipeline, AutoTokenizer, AutoModelForTokenClassification | |
| def demo_sentiment(): | |
| clf = pipeline("sentiment-analysis", model="YOUR-USERNAME/Finance-NLP-Toolkit") | |
| print(clf("Shares plunged after the weak revenue outlook.")) | |
| def demo_ner(): | |
| tok = AutoTokenizer.from_pretrained("YOUR-USERNAME/Finance-NLP-Toolkit", revision="ner") | |
| ner_model = AutoModelForTokenClassification.from_pretrained("YOUR-USERNAME/Finance-NLP-Toolkit", revision="ner") | |
| ner = pipeline("token-classification", model=ner_model, tokenizer=tok, aggregation_strategy="simple") | |
| print(ner("Microsoft will acquire Nuance for $19.7 billion in 2025.")) | |
| if __name__ == "__main__": | |
| demo_sentiment() | |
| demo_ner() | |