Created
February 5, 2021 04:06
-
-
Save sweemeng/d82c0abd64f7cff3e69b7310459a7ff7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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