Skip to content

Instantly share code, notes, and snippets.

@sweemeng
Created February 5, 2021 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sweemeng/d82c0abd64f7cff3e69b7310459a7ff7 to your computer and use it in GitHub Desktop.
Save sweemeng/d82c0abd64f7cff3e69b7310459a7ff7 to your computer and use it in GitHub Desktop.
from transformers import pipeline
import requests
import pprint
def load_hn():
hn_feed = requests.get("https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty")
data = hn_feed.json()
return data
def main():
classifier = pipeline("zero-shot-classification")
classes = ['tech', 'programming', 'web', 'coding']
data = load_hn()
for item_id in data[:20]:
url = f"https://hacker-news.firebaseio.com/v0/item/{item_id}.json?print=pretty"
item_feed = requests.get(url)
feed_data = item_feed.json()
title = feed_data['title']
result = classifier(title, classes)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(result)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment