File size: 783 Bytes
c81b9f6 31c0940 c81b9f6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | """Minimal Tallie example. Run from inside the downloaded model folder: python example.py"""
from pathlib import Path
from tallie import Tallie
here = Path(__file__).parent
t = Tallie.load(here)
comments = [
"Planet Money and EconTalk are the two podcasts I never skip.",
"I tried 1Q84 twice and gave up, it's so slow.",
"Honestly 99% Invisible is the best podcast out there.",
"EconTalk changed how I think about economics.",
]
for item in t.extract(comments):
print(f"{item['text']:20s} type={item['type']:10s} opinion={item['polarity']}")
t.index(comments)
for q in ["podcasts people recommend", "books people disliked"]:
print("\n" + q)
for r in t.ask(q)["results"]:
print(f" {r['item']:20s} {r['mentions']} mention(s) {r['polarity']}")
|