[Python] Not able to generate output on certain reviews by using fine-tune model

Discussão em 'Python' iniciado por Stack, Maio 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using T5, a text-to-text model for performing spell checks in a given dataset consisting of reviews. The model is fine-tuned in 2 iterations of 20k reviews and 40k reviews each. The training loss and validation loss in this entire process was 0.0003 and 0.000052 respectively. Now after this I have applied this on a sample list of 20 reviews just to manually check its performance which was decent enough, but when applying to the dataset, which has about more than 14k reviews, the model did not show any output for 1.1k reviews ?

    I'm attaching my code below where I'm implementing this

    class ReviewDataset(Dataset):
    def __init__(self, texts):
    self.inputs = ["fix: " + text for text in texts]

    def __len__(self):
    return len(self.inputs)

    def __getitem__(self, idx):
    return self.inputs[idx]

    def collate_fn(batch):
    encodings = tokenizer(
    batch,
    padding=True,
    truncation=True,
    max_length=128,
    return_tensors="pt"
    )
    return encodings


    I have implemented this by batch processing

    df = pd.read_csv("reviews.csv",encoding="latin-1")
    dataset = ReviewDataset(df["review_text"].tolist())
    dataloader = DataLoader(dataset, batch_size=256, collate_fn=collate_fn)


    all_predictions = []

    with torch.no_grad():
    for batch in dataloader:
    input_ids = batch["input_ids"].to(device)
    attention_mask = batch["attention_mask"].to(device)

    outputs = model.generate(input_ids=input_ids, attention_mask=attention_mask, max_length=64)
    decoded = tokenizer.batch_decode(outputs, skip_special_tokens=True)
    all_predictions.extend(decoded)

    df["corrected_review"] = all_predictions
    df.to_csv("corrected_reviews_batched.csv", index=False)


    How can I fix this ?

    Continue reading...

Compartilhe esta Página