MaartenGr / MaartenGr/PolyFuzz

How to use PolyFuzz with T5 model?

Open
#58 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
803
Forks
72
PR merge metrics
No merged PRs in 30d

Description

I am learning the use case of polyfuzz with T5 embedding.
I am getting error when using following code:

```
polyfuzz: 0.4.0
transformers: 4.26.1
torch: 1.13.1+cu117
tensorflow: 2.11.0
tensorflow_hub: 0.12.0
```
# MWE
```python
import torch
import numpy as np
import polyfuzz
from transformers import T5Tokenizer, T5ForConditionalGeneration

# Load the T5 model and tokenizer
model_name = 't5-small'
model = T5ForConditionalGeneration.from_pretrained(model_name)
tokenizer = model.from_pretrained(model_name)

# Define your target and candidate strings
target_strings = ['The quick brown fox jumps over the lazy dog', 'The sky is blue']
candidate_strings = ['The fox is quick and the dog is lazy', 'The ocean is blue']

# Tokenize the strings and convert them to T5 embeddings
target_tokens = tokenizer.batch_encode_plus(target_strings, padding=True, truncation=True, return_tensors='pt')
candidate_tokens = tokenizer.batch_encode_plus(candidate_strings, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
target_embeddings = model.encoder(input_ids=target_tokens['input_ids']).last_hidden_state.detach().numpy()
candidate_embeddings = model.encoder(input_ids=candidate_tokens['input_ids']).last_hidden_state.detach().numpy()

# Create a PolyFuzz object with default settings
model = polyfuzz.PolyFuzz()

# Fit the model with the T5 embeddings
model.fit(target_embeddings, candidate_embeddings)

# Get the matches between the target and candidate strings
matches = model.get_matches()
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the MWE with the listed package versions, beginning at tokenizer/model creation and the call to model.fit(...). Check PolyFuzz's expected fit inputs against the T5 encoder output, and capture the exception that is omitted from the report. Done means the issue has confirmed compatible usage or a documented incompatibility with a minimal example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.