YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

How to load the model and make inferences

Download all the files to a local directory model_dir

Load the model and the tokenizers

from transformers import BartForConditionalGeneration, BartConfig, BartTokenizer, PreTrainedTokenizerFast
tokenizer_w2p = PreTrainedTokenizerFast.from_pretrained(model_dir)
model_w2p = BartForConditionalGeneration.from_pretrained(model_dir)

Inference

Set seed and create inference function (batch)

import random
import numpy as np
import torch

def set_seed(seed=42):
    torch.manual_seed(seed)
    random.seed(seed)
    np.random.seed(seed)
    if torch.cuda.is_available():
        torch.cuda.manual_seed_all(seed)
        torch.backends.cudnn.deterministic = True
        torch.backends.cudnn.benchmark = False

def g2p_local(sentence, model, tokenizer):
    set_seed(42)
    model.eval()
    batched_inputs = sentence.split()
    # will produced a list of words that are space separated
    batched_inputs = [" ".join(list(w)) for w in batched_inputs]
    inputs = tokenizer(batched_inputs, return_tensors="pt", padding=True, truncation=True, max_length=32)
    with torch.no_grad():
        output_ids = model.generate(
        input_ids=inputs["input_ids"],
        attention_mask=inputs["attention_mask"],
        max_length=32,
        num_beams=5,         # You can adjust decoding strategy
        early_stopping=True
        )
    decoded_outputs = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
    decoded_outputs = [r.replace(" ", "") for r in decoded_outputs]
    
    return " ".join(decoded_outputs)

The inference function:

text = "It's raining cats and dogs."
result = g2p_local(text, model_w2p, tokenizer_w2p)  

This should return:

'ˌɪts ɹˈAnɪŋ kˈæts ænd dˈɔɡz.'
Downloads last month
4
Safetensors
Model size
10.5M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support