In [ ]:
import os; os.chdir('..')
In [ ]:
from keys import get_similarity_against
In [ ]:
In [ ]:
main_query= "best cat ear headphones"
In [ ]:
sentence1= '''When you talk about cat ear headphones or headphones in general, you just couldn’t avoid talking about Razer and their Kraken Kitty. The Razer Kraken Kitty is the cat-eared representative of the notorious Razer Kraken Family.
The Kraken line features Razer headphones for gamers on a budget. This line headlines an immersive audio experience to go with other features essential for gamers. If you’re interested in some of these non-cat ear headphones, you can check out our review for the Razer Kraken v2 and the Kraken X Lite.
The Kraken Kitty are wired gaming headphones that connect through a USB-A type of connection. If you’re more of a wireless person, you’ll be glad to know that these headphones also come with a Bluetooth-ready variant.
These headphones feature Razer Chroma LED Lights from ear cup to cat ears. Razer Chroma is Razer’s proprietary RGB light system that features 16.8 million colors, patterns, and in-game lighting effects. You can easily customize this through the Chroma Studio while additional interactive effects can be set through the Streamer Companion App.
Much like the others in the Kraken family, the Kraken Kitty feature the THX Spatial Audio. This is a 7.1 surround sound system that lets you stand right in the middle of the action. They also feature Razer’s noise-cancelling HyperClear Cardioid Microphone. Say goodbye to the excuses made by your teammates about not hearing you.'''
sentence2= '''When delving into the realm of Feline-themed audio headgear, one simply cannot sidestep the discourse surrounding Razer and their Kraken Kitty. The Razer Kraken Kitty stands as the feline-embellished envoy within the infamous Razer Kraken lineage.
The Kraken series showcases Razer's headphones tailored for frugal gamers. This collection takes center stage in providing an immersive auditory journey, replete with indispensable gamer-centric features. If you happen to be intrigued by headphones sans the feline embellishments, peruse our evaluation of the Razer Kraken v2 and the Kraken X Lite.
The Kraken Kitty, meanwhile, serves as a wired gaming headset, employing a USB-A interface for connectivity. For those who lean toward wireless options, it's worth noting that these headphones also offer a Bluetooth-enabled iteration.
These headphones boast Razer Chroma LED illumination, adorning both ear cups and feline-inspired appendages. Razer Chroma represents the proprietary RGB light system of Razer, boasting an array of 16.8 million colors, intricate patterns, and in-game lighting effects. Customization options abound via the Chroma Studio, while further interactive effects can be configured through the Streamer Companion App.
In a manner akin to its Kraken kin, the Kraken Kitty incorporates THX Spatial Audio, a 7.1 surround sound system that transports you directly into the heart of the gaming action. Furthermore, these headphones feature Razer's noise-cancellation technology, the HyperClear Cardioid Microphone, putting an end to any excuses from your gaming comrades regarding audio clarity.'''
In [ ]:
sentence1
Out[ ]:
'When you talk about cat ear headphones or headphones in general, you just couldn’t avoid talking about Razer and their Kraken Kitty. The Razer Kraken Kitty is the cat-eared representative of the notorious Razer Kraken Family.\n\nThe Kraken line features Razer headphones for gamers on a budget. This line headlines an immersive audio experience to go with other features essential for gamers. If you’re interested in some of these non-cat ear headphones, you can check out our review for the Razer Kraken v2 and the Kraken X Lite.\nThe Kraken Kitty are wired gaming headphones that connect through a USB-A type of connection. If you’re more of a wireless person, you’ll be glad to know that these headphones also come with a Bluetooth-ready variant.\n\nThese headphones feature Razer Chroma LED Lights from ear cup to cat ears. Razer Chroma is Razer’s proprietary RGB light system that features 16.8 million colors, patterns, and in-game lighting effects. You can easily customize this through the Chroma Studio while additional interactive effects can be set through the Streamer Companion App.\n\nMuch like the others in the Kraken family, the Kraken Kitty feature the THX Spatial Audio. This is a 7.1 surround sound system that lets you stand right in the middle of the action. They also feature Razer’s noise-cancelling HyperClear Cardioid Microphone. Say goodbye to the excuses made by your teammates about not hearing you.'
In [ ]:
sentence2
Out[ ]:
"When delving into the realm of Feline-themed audio headgear, one simply cannot sidestep the discourse surrounding Razer and their Kraken Kitty. The Razer Kraken Kitty stands as the feline-embellished envoy within the infamous Razer Kraken lineage.\n\nThe Kraken series showcases Razer's headphones tailored for frugal gamers. This collection takes center stage in providing an immersive auditory journey, replete with indispensable gamer-centric features. If you happen to be intrigued by headphones sans the feline embellishments, peruse our evaluation of the Razer Kraken v2 and the Kraken X Lite.\n\nThe Kraken Kitty, meanwhile, serves as a wired gaming headset, employing a USB-A interface for connectivity. For those who lean toward wireless options, it's worth noting that these headphones also offer a Bluetooth-enabled iteration.\n\nThese headphones boast Razer Chroma LED illumination, adorning both ear cups and feline-inspired appendages. Razer Chroma represents the proprietary RGB light system of Razer, boasting an array of 16.8 million colors, intricate patterns, and in-game lighting effects. Customization options abound via the Chroma Studio, while further interactive effects can be configured through the Streamer Companion App.\n\nIn a manner akin to its Kraken kin, the Kraken Kitty incorporates THX Spatial Audio, a 7.1 surround sound system that transports you directly into the heart of the gaming action. Furthermore, these headphones feature Razer's noise-cancellation technology, the HyperClear Cardioid Microphone, putting an end to any excuses from your gaming comrades regarding audio clarity."
Method 1: Direct Similarity of Embeddings
¶
In [ ]:
import requests
import json
In [ ]:
response= requests.post(url= "https://embeddings.paperbot.ai/get-similarity-against",
json={
"main_entity": main_query,
"compare_with": [sentence1, sentence2]
})
In [ ]:
json.loads(response.content.decode("utf-8"))['similarity']
Out[ ]:
[0.86, 0.84]
Method 1: BERT Question-Answering
¶
In [ ]:
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
model_name = "deepset/roberta-base-squad2"
# a) Get predictions
nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
/home/ubuntu/SentenceStructureComparision/venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm Downloading (…)lve/main/config.json: 100%|██████████| 571/571 [00:00<00:00, 4.19MB/s] Downloading model.safetensors: 100%|██████████| 496M/496M [00:01<00:00, 346MB/s] Downloading (…)okenizer_config.json: 100%|██████████| 79.0/79.0 [00:00<00:00, 488kB/s] Downloading (…)olve/main/vocab.json: 100%|██████████| 899k/899k [00:00<00:00, 59.0MB/s] Downloading (…)olve/main/merges.txt: 100%|██████████| 456k/456k [00:00<00:00, 91.6MB/s] Downloading (…)cial_tokens_map.json: 100%|██████████| 772/772 [00:00<00:00, 4.00MB/s]
In [ ]:
QA_input = {
'question': main_query,
'context': sentence1
}
res = nlp(QA_input)
res
Out[ ]:
{'score': 0.007429047022014856, 'start': 103, 'end': 131, 'answer': 'Razer and their Kraken Kitty'}
In [ ]:
QA_input = {
'question': main_query,
'context': sentence2
}
res = nlp(QA_input)
res
Out[ ]:
{'score': 0.0018078010762110353, 'start': 130, 'end': 142, 'answer': 'Kraken Kitty'}
In [ ]:
In [ ]:
In [ ]:
Method 3: Summarization via Language Model
¶
In [ ]:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("summarization", model="DunnBC22/flan-t5-base-text_summarization_data", device="cuda")
In [ ]:
pipe([sentence1, sentence2], min_length=50, max_length=200)
Out[ ]:
[{'summary_text': 'Razer Kraken Kraken Kitty is the cat-eared representative of the Razers Kraken Family. The Kraken line features Razer headphones for gamers on a budget. These headphones feature Razer Chroma LED Lights from ear cup to cat ears. They also feature THX Spatial Audio.'}, {'summary_text': "Razer's Kraken Kraken Kitty is a collection of Razer headphones designed for frugal gamers. The Kraken X Lite is wired and offers a Bluetooth-enabled iteration. These headphones feature Razer Chroma LED illumination, adorning both ear cups and feline-inspired appendages."}]
In [ ]:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("summarization", model="google/pegasus-cnn_dailymail", device="cuda")
In [ ]:
pipe([sentence1, sentence2], min_length=50, max_length=200)
Out[ ]:
[{'summary_text': 'Cat ear headphones are popular among otakus, streamers, gamers, and anyone who wants a uniquely cute look .<n>Design is the priority, but sound quality should also be considered .'}, {'summary_text': 'Feline-themed audio headgear enjoys favor among aficionados of anime and gaming, as well as content creators .<n>Seek out headphones delivering crystal-clear and precise audio, and assess their suitability for both mature users and youngsters'}]
In [ ]: