Challenges with semantic search on transcribed audio information
Moving from SQLite to Chroma⌗
I’ve been searching for a extra environment friendly approach of implementing semantic
search on my command line YouTube search engine yt-fts. I
was initially storing the embeddings within the sqlite database,
which concerned changing the embeddings to blob information after which
changing them again to arrays when studying them from the database.
# Convert embeddings to blob information
embedding = get_embedding(api_key, textual content)
embeddings_blob = pickle.dumps(embedding)
cur.execute(""" INSERT INTO Embeddings (subtitle_id, video_id, timestamp, textual content, embeddings)
VALUES (?, ?, ?, ?, ?)
""", [subtitle_id, video_id, timestamp, text, embeddings_blob])
# Convert embeddings again to array
db_embedding = pickle.masses(row[4]) similarity = cosine_similarity([search_embedding], [db_embedding])
Obviously, this doesn’t scale nicely. The channel 3Brown1Blue has
127 movies and 51,751 rows within the Subtitles desk which implies
I program must convert 51,751 embeddings to blob information
after which convert them again to arrays when looking out which might
take over 20 seconds.
chromadb is a vector search database that tremendously accelerates this
activity and it was fairly plug and play combine in my challenge
Instead of including the embeddings to my sqlite database we simply add
them to the chroma vector retailer with the accompanying metadata.
No have to convert to blob information
embedding = get_embedding(textual content)
meta_data = {
"channel_id": channel_id,
"video_id": video_id,
"start_time": start_time,
}
assortment.add(
paperwork=[text],
embeddings=[embedding],
metadatas=[meta_data],
ids=[subtitle_id],
)
And for looking out chroma handles the similarity perform
res = assortment.question(
query_embeddings=[search_embedding],
n_results=restrict,
the place={"video_id": video_id},
)
Quality of outcomes⌗
While chroma considerably accelerates the search outcomes it
doesn’t improve the “high quality” of the outcomes.
For instance if we’re trying to find a component in 3brown1Blues video on
again propagation, particularly the place he explains how the chain rule
pertains to again propagation, which is roughly at 06:30 of the
video "Backpropagation calculus | Chapter 4, Deep studying".
Our sematic search question would possibly look one thing like this
yt-fts vsearch -c "3Blue1Brown" "backpropagation chain rule relation Neural community"
The VTT file of this part seems like this:
00:06:30.310 --> 00:06:30.320
immediately affect that earlier layer
00:06:32.440 --> 00:06:32.450
activation it is useful to maintain monitor of
00:06:34.930 --> 00:06:34.940
as a result of now we are able to simply maintain iterating
00:06:38.290 --> 00:06:38.300
this identical chain rule thought backwards to
And seems like this on our Subtitles desk
00:06:30.310|immediately affect that earlier layer
00:06:32.440|activation it is useful to maintain monitor of
00:06:34.930|as a result of now we are able to simply maintain iterating
00:06:38.290|this identical chain rule thought backwards to
3Blue1Brows channel creates over 51k subtitles within the Subtitles
desk, the textual content in every row will get transformed into an embedding.
Because youtube splits every subtitle by comparatively brief
two second intervals, our semantic search is tremendously restricted
by the dearth of context.
The similarity rating of the phrases "chain rule" will likely be excessive on the
row containing "this identical chain rule thought backwards to" which has
no relation to the opposite rows. And "Neural community" would have
a excessive similarity rating if "layer activation" was in a single row
however they’re not.
The entice of grouping by phrase rely⌗
The deceptively simple answer to that is merely grouping subtitles by
a set token size or phrase rely and utilizing the beginning time stamp as
the delimiter. This works for written textual content as a result of the dialog
velocity of written textual content is at all times constant. However, our dataset
derived from spoken phrases and the size of every entry will range
drastically relying on the velocity of the individual talking.
Splitting by time⌗
My present answer to that is to separate the subtitles by 10 second
intervals. I unscientifically selected 10 seconds as a result of I figured that’s
about how lengthy folks would wait to see if the search outcomes had been
related. This has a aspect impact of constructing the strings within the
search outcomes for much longer.
"immediately affect that earlier layer activation it is useful to maintain monitor of as a result of now we are able to simply maintain iterating this identical chain rule thought backwards to"
Distance: 0.3714187741279602
Channel: 3Blue1Brown - (UCYO_jab_esuFRV4b17AJtAw)
Title: Backpropagation calculus | Chapter 4, Deep studying - YouTube
Time Stamp: 00:06:30.310
Video ID: tIeHLnjs5U8
Link: https://youtu.be/tIeHLnjs5U8?t=387
"of backpropagation the workhorse behind how neural networks be taught these chain rule expressions provide the derivatives that decide every element within the gradient that helps"
Distance: 0.28358280658721924
Channel: 3Blue1Brown - (UCYO_jab_esuFRV4b17AJtAw)
Title: Backpropagation calculus | Chapter 4, Deep studying - YouTube
Time Stamp: 00:09:21.370
Video ID: tIeHLnjs5U8
Link: https://youtu.be/tIeHLnjs5U8?t=558
It can also be nonetheless not as correct accurately, if it had the total
context of the video to work with. The first result’s from the place
the 3Blue1Brown is summarizing what the video was about slightly than
the precise clarification.
Langchain⌗
I briefly thought-about borrowing from Langchain’s SRTLoader
class loader as an answer (srt is an identical format to vtt)
however it falls into the identical entice of ignoring “when” one thing was stated.
I received’t go an excessive amount of into the small print of how langchain masses
arbitrary paperwork however it’s essential to notice that vtt information
are learn as textual content information so DirectoryLoader will simply create
a chroma entry for at max 150 phrases treating them as paragraphs.
from langchain.document_loaders import DirectoryLoader
from langchain.indexes import VectorstoreIndexCreator
data_path = "3Brow1Blue_vtt"
loader = DirectoryLoader(data_path)
index = VectorstoreIndexCreator(vectorstore_kwargs={
"persist_directory": "persist_vtt"
}).from_loaders([loader])
This is how we might question the chroma database made by
langchain and get the highest outcome
question = "backpropagation chain rule relation Neural community"
search_embedding = get_embedding(question)
chroma_res = assortment.question(
query_embeddings=[search_embedding],
n_results=1
)
textual content = chroma_res["documents"][0][0].change("nn", "n")
word_count = len(textual content.cut up(" "))
print(textual content)
print(f"phrase rely: {word_count}")
The output of this reveals that langchain get’s precisely what we’re
searching for.
Page Content:
00:06:30.310 --> 00:06:30.320 immediately affect that earlier layer
00:06:32.440 --> 00:06:32.450 activation it is useful to maintain monitor of
00:06:34.930 --> 00:06:34.940 as a result of now we are able to simply maintain iterating
00:06:38.290 --> 00:06:38.300 this identical chain rule thought backwards to
00:06:40.180 --> 00:06:40.190 see how delicate the fee perform is
00:06:42.430 --> 00:06:42.440 to earlier weights and former biases
00:06:44.740 --> 00:06:44.750 and also you would possibly assume that that is an
00:06:46.660 --> 00:06:46.670 overly easy instance since all layers
00:06:48.340 --> 00:06:48.350 simply have one neuron and that issues are
00:06:49.450 --> 00:06:49.460 going to get exponentially extra
00:06:51.730 --> 00:06:51.740 sophisticated for an actual community however
00:06:54.190 --> 00:06:54.200 truthfully not that a lot modifications once we
00:06:56.440 --> 00:06:56.450 give the layers a number of neurons actually
00:06:58.090 --> 00:06:58.100 it is only a few extra indices to maintain
phrase rely: 122
The first drawback with that is that the returned textual content is in a 30
second window. I received fortunate with the primary subtitle begin time
being the instance precisely the one I wished but when we had been trying
for textual content that begins at 06:48 the consumer must wait 18
seconds to comprehend it was the precise outcome.
The second drawback with that is that we don’t know the size of this
window as a result of the time stamps are saved within the search textual content, which means
they’re additionally saved as embeddings. There’s no assure that the openAI
embedding mannequin is aware of that "00:06:30.310 --> 00:06:30.320"is metadata
and to not affiliate it with the textual content within the subtitle.
I attempted feeding this again into gpt with this perform however I stored
getting inconsistent outcomes
def get_most_relevant_snippet(question, vtt_snippets): proompt = f"""
Given the next question and checklist of vtt traces, please return the only most related line to the question.
Query: "{question}"
VTT Snippets:
{vtt_snippets}
"""
responce = shopper.completions.create(
mannequin="gpt-3.5-turbo-instruct",
immediate=proompt
)
return responce.selections[0].textual content
outputs:
strive 1:
00:06:38.290 --> 00:06:38.
strive 2:
The most related line to the question could be:
00:
strive 3:
I'm sorry, I can't full this immediate because it violates OpenAI's
Speculative answer⌗
Even if this my proompt engineering labored, it wouldn’t repair the actual fact
that I’m arbitrarily splitting the textual content. An supreme answer would
cut up up the dataset utilizing each the which means of the entire textual content and the
time-frame of when it was stated. The search course of ought to by some means
iteratively slender down the right place to begin. Perhaps this
course of would require producing new embeddings on the fly?
I don’t know, and for those who occur to have any concepts be happy to
make a PR on yt-fts
Thanks for studying.
HI-FI News
through Hacker News https://ift.tt/uGasjq3
December 30, 2023 at 02:40AM
-
Product on sale
Audiophile Vinyl Records Cleaning BundleOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Product on sale
Easy Start Vinyl Records Cleaning KitOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Vinyl Records Cleaner Easy Groove Concentrate€34.95 incl. VAT -
Easy Groove Super Set€199.00 incl. VAT -
Easy Groove Enzycaster – vinyl records prewash cleaner€34.95 incl. VAT -
Easy Groove Extreme MK. II- vinyl records prewash cleaner€45.00 incl. VAT -
Vinyl Records Cleaner – Easy Groove Virgin Concentrate€35.00 incl. VAT -
Easy Groove Spray&Wipe vinyl records cleaner€34.95 incl. VAT








