Created
July 30, 2021 21:35
-
-
Save davidmezzetti/17b8ed9935617d14e4ddf4e7796281a1 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
| # pip install txtai | |
| from txtai.embeddings import Embeddings | |
| import requests | |
| # Embeddings with sentence-transformers backend | |
| embeddings = Embeddings({"method": "transformers", "path": "sentence-transformers/paraphrase-mpnet-base-v2"}) | |
| # Query HN | |
| data = [x["title"] for x in requests.get("https://hn.algolia.com/api/v1/search?tags=front_page").json()["hits"]] | |
| # Get best matches for topic | |
| print([data[uid] for uid, score in embeddings.similarity("programming", data) if score >= 0.3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment