def embedding_function(texts, model="text-embedding-ada-002"):
if isinstance(texts, str):
texts = [texts]
texts = [t.replace("\n", " ") for t in texts]
return [data.embedding for data in openai.embeddings.create(input = texts, model=model).data]vector_store = VectorStore(
path = vector_store_path,
)
vector_store.add(text = chunked_text,
embedding_function = embedding_function,
embedding_data = chunked_text,
metadata = metadata
) tensor htype shape dtype compression
------- ------- ------- ------- -------
embedding embedding (21055, 1536) float32 None
id text (21055, 1) str None
metadata json (21055, 1) str None
text text (21055, 1) str None # vector_store.add(text = chunked_text,
# embedding = <list_of_embeddings>,
# metadata = [{"source": source_text}]*len(chunked_text))prompt = "What do trust and safety models do?"
search_results = vector_store.search(embedding_data=prompt, embedding_function=embedding_function)len(search_results['text'])
# Returns 4search_results['text'][0]Trust and Safety Models
=======================
We decided to open source the training code of the following models:
- pNSFWMedia: Model to detect tweets with NSFW images. This includes adult and porn content.
- pNSFWText: Model to detect tweets with NSFW text, adult/sexual topics.
- pToxicity: Model to detect toxic tweets. Toxicity includes marginal content like insults and certain types of harassment. Toxic content does not violate Twitter's terms of service.
- pAbuse: Model to detect abusive content. This includes violations of Twitter's terms of service, including hate speech, targeted harassment and abusive behavior.
We have several more models and rules that we are not going to open source at this time because of the adversarial nature of this area. The team is considering open sourcing more models going forward and will keep the community posted accordingly.search_results['metadata'][0]
# Returns: {'filepath': '/the-algorithm/trust_and_safety_models/README.md'}search_results = vector_store.search(embedding_data=prompt,
embedding_function=embedding_functiondding,
k=10,
distance_metric='l2')len(search_results['text'])
# Returns: 10search_results['text'][0]Trust and Safety Models
=======================
We decided to open source the training code of the following models:
- pNSFWMedia: Model to detect tweets with NSFW images. This includes adult and porn content.
- pNSFWText: Model to detect tweets with NSFW text, adult/sexual topics.
- pToxicity: Model to detect toxic tweets. Toxicity includes marginal content like insults and certain types of harassment. Toxic content does not violate Twitter's terms of service.
- pAbuse: Model to detect abusive content. This includes violations of Twitter's terms of service, including hate speech, targeted harassment and abusive behavior.
We have several more models and rules that we are not going to open source at this time because of the adversarial nature of this area. The team is considering open sourcing more models going forward and will keep the community posted accordingly.vector_store = VectorStore(
path = "hub://activeloop/twitter-algorithm",
read_only=True
)prompt = "What do trust and safety models do?"
embedding = embedding_function(prompt)[0]
# Format the embedding array or list as a string, so it can be passed in the REST API request.
embedding_string = ",".join([str(item) for item in embedding])
tql_query = f"select * from (select text, cosine_similarity(embedding, ARRAY[{embedding_string}]) as score) order by score desc limit 5"search_results = vector_store.search(query=tql_query)search_results['text'][0]Trust and Safety Models
=======================
We decided to open source the training code of the following models:
- pNSFWMedia: Model to detect tweets with NSFW images. This includes adult and porn content.
- pNSFWText: Model to detect tweets with NSFW text, adult/sexual topics.
- pToxicity: Model to detect toxic tweets. Toxicity includes marginal content like insults and certain types of harassment. Toxic content does not violate Twitter's terms of service.
- pAbuse: Model to detect abusive content. This includes violations of Twitter's terms of service, including hate speech, targeted harassment and abusive behavior.
We have several more models and rules that we are not going to open source at this time because of the adversarial nature of this area. The team is considering open sourcing more models going forward and will keep the community posted accordingly.print(search_results['metadata'][0])
# Returns {'filepath': '/Users/istranic/ActiveloopCode/the-algorithm/trust_and_safety_models/README.md', 'extension': '.md'}