mirror of
https://github.com/neuml/txtai.git
synced 2026-10-11 21:39:55 +00:00
13 KiB
13 KiB
In [1]:
%%capture
!pip install git+https://github.com/neuml/txtai#egg=txtai[ann,vectors]In [2]:
from txtai import Embeddings
# Works with a list, dataset or generator
data = [
"US tops 5 million confirmed virus cases",
"Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg",
"Beijing mobilises invasion craft along coast as Taiwan tensions escalate",
"The National Park Service warns against sacrificing slower friends in a bear attack",
"Maine man wins $1M from $25 lottery ticket",
"Make huge profits without work, earn up to $100,000 a day"
]
# Create an embeddings
embeddings = Embeddings(sparse=True, content=True)
embeddings.index(data)
embeddings.search("North America", 10)Out [2]:
[{'id': '0',
'text': 'US tops 5 million confirmed virus cases',
'score': 0.019873601198196412},
{'id': '1',
'text': "Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg",
'score': 0.018737798929214476}]In [3]:
from txtai import Embeddings
# Works with a list, dataset or generator
data = [
"US tops 5 million confirmed virus cases",
"Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg",
"Beijing mobilises invasion craft along coast as Taiwan tensions escalate",
"The National Park Service warns against sacrificing slower friends in a bear attack",
"Maine man wins $1M from $25 lottery ticket",
"Make huge profits without work, earn up to $100,000 a day"
]
# Create an embeddings
embeddings = Embeddings(path="colbert-ir/colbertv2.0", content=True)
embeddings.index(data)
embeddings.search("North America", 10)Out [3]:
[{'id': '0',
'text': 'US tops 5 million confirmed virus cases',
'score': 0.04216160625219345},
{'id': '1',
'text': "Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg",
'score': 0.029944246634840965},
{'id': '3',
'text': 'The National Park Service warns against sacrificing slower friends in a bear attack',
'score': 0.015931561589241028}]In [4]:
from txtai import Embeddings
from txtai.pipeline import Reranker, Similarity
# Works with a list, dataset or generator
data = [
"US tops 5 million confirmed virus cases",
"Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg",
"Beijing mobilises invasion craft along coast as Taiwan tensions escalate",
"The National Park Service warns against sacrificing slower friends in a bear attack",
"Maine man wins $1M from $25 lottery ticket",
"Make huge profits without work, earn up to $100,000 a day"
]
# Create an embeddings
embeddings = Embeddings(path="colbert-ir/colbertv2.0", content=True)
embeddings.index(data)
similarity = Similarity(path="colbert-ir/colbertv2.0", lateencode=True)
ranker = Reranker(embeddings, similarity)
ranker("North America")Out [4]:
[{'id': '1',
'text': "Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg",
'score': 0.3324427008628845},
{'id': '0',
'text': 'US tops 5 million confirmed virus cases',
'score': 0.24423550069332123},
{'id': '3',
'text': 'The National Park Service warns against sacrificing slower friends in a bear attack',
'score': 0.16353240609169006}]In [5]:
from txtai import Embeddings
from txtai.pipeline import Reranker, Similarity
# Create an embeddings
embeddings = Embeddings()
embeddings.load(provider="huggingface-hub", container="neuml/txtai-wikipedia")
similarity = Similarity(path="colbert-ir/colbertv2.0", lateencode=True)
ranker = Reranker(embeddings, similarity)
ranker("Tell me about ChatGPT")Out [5]:
[{'id': 'ChatGPT',
'text': 'ChatGPT is a generative artificial intelligence chatbot developed by OpenAI and released on November 30, 2022. It uses large language models (LLMs) such as GPT-4o as well as other multimodal models to create human-like responses in text, speech, and images. It has access to features such as searching the web, using apps, and running programs. It is credited with accelerating the AI boom, an ongoing period of rapid investment in and public attention to the field of artificial intelligence (AI). Some observers have raised concern about the potential of ChatGPT and similar programs to displace human intelligence, enable plagiarism, or fuel misinformation.',
'score': 0.6639302968978882},
{'id': 'ChatGPT Search',
'text': 'ChatGPT Search (originally SearchGPT) is a search engine developed by OpenAI. It combines traditional search engine features with generative pretrained transformers (GPT) to generate responses, including citations to external websites.',
'score': 0.6477508544921875},
{'id': 'ChatGPT in education',
'text': 'The usage of ChatGPT in education has sparked considerable debate and exploration. ChatGPT is a chatbot based on large language models (LLMs) that was released by OpenAI in November 2022.',
'score': 0.5918337106704712}]