More modalities - #2542
Draft
MaartenGr wants to merge 4 commits into
Draft
More modalities#2542MaartenGr wants to merge 4 commits into
MaartenGr wants to merge 4 commits into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add audio, video, and code as modalities
Yes, even code. I'm thinking I would like to treat code as a separate modality. The reason for that is mostly recognition. If it's treated as text, then it would be difficult to recognize and potentially create different tokenizers/processors for that entity. Not sure if it's a good idea, but let's do it anyway 😉
I'm trying to separate this by looking at if from two perspectives:
Embeddings
audio=,video=andcode=are parameters added tofit,fit_transform,transform,update_topics,merge_topics,reduce_topicsandreduce_outliers.documentsis now optional.documents=withimages=always did. Otherwise, each document and each media item is its own row.MultiModalBackendtakes a model per modality (image_model,audio_model,video_model,code_model), withembedding_modelas the fallback. This will make it possible to use multimodal embedding models on various modalities (typically image + text) or choose a single modality to be embedded (like using semble / potion models, which I love)Labeling topics
MultiModalRepresentationreplacesVisualRepresentationbecause I think it should capture all modalities and have standard strategies for each modality supported. It captions images and video frames with anyimage-text-to-textmodel and transcribes audio with a speech-recognition model such as Whisper, or with any callable, so a corpus of media alone still gets keywords.Mediarepresentation.get_topic_info()shows them asRepresentative_Items,representative_items_sits besiderepresentative_docs_, andrepresentative_images_holds the collages <-- Not sure about this one yet and will have to test it out quite a bit.Breaking changes
VisualRepresentationbecomesMultiModalRepresentation(model=...).MultiModalBackend.embed_imagesbecomesembed_media(images, "image").embed(docs, images)no longer averages the two;fit_transform(documents=..., images=...)does that.Representative_Itemsinstead of in a column named after its aspect.New extras:
bertopic[audio](librosa, soundfile) andbertopic[video](torchcodec).Note: media and text passed as separate rows tend to form separate topics, because embedding models place each modality in its own region (the modality gap). Pairs don't have this problem, since each pair is one averaged row. This was an interesting experiment but differs highly between models. Something to document though.