Summarization
Transformers
PyTorch
Safetensors
Italian
t5
text2text-generation
tags
Italian
text-generation-inference
Run this model with HF Jobs
Run efederici/text2tags on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/efederici/text2tags. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/efederici/text2tags on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use efederici/text2tags with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use efederici/text2tags with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "summarization" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # pip install "transformers<5.0.0" from transformers import pipeline pipe = pipeline("summarization", model="efederici/text2tags")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("efederici/text2tags") model = AutoModelForSeq2SeqLM.from_pretrained("efederici/text2tags", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files53 unmodified lines54555657585953 unmodified linesprint(tags)```### Overview- Model: T5 ([it5-small](https://huggingface.co/gsarti/it5-small))53 unmodified lines5455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213353 unmodified linesprint(tags)```## Longer documentsAssuming paragraphs are divided by: '\n\n'.```pythonfrom transformers import T5ForConditionalGeneration,T5Tokenizerimport itertoolsimport remodel = T5ForConditionalGeneration.from_pretrained("efederici/text2tags")tokenizer = T5Tokenizer.from_pretrained("efederici/text2tags")article = '''Da bambino era preoccupato che al mondo non ci fosse più nulla da scoprire. Ma i suoi stessi studi gli avrebbero dato torto: insieme a James Watson, nel 1953 Francis Crick strutturò il primo modello di DNA, la lunga sequenza di codici che identifica ogni essere vivente, rendendolo unico e diverso da tutti gli altri.La scoperta gli valse il Nobel per la Medicina. È uscita in queste settimane per Codice la sua biografia, Francis Crick — Lo scopritore del DNA, scritta da Matt Ridley, che racconta vita e scienza dell'uomo che capì perché siamo fatti così.'''def words(text):input_str = textoutput_str = re.sub('[^A-Za-z0-9]+', ' ', input_str)return output_str.split()def is_subset(text1, text2):return all(tag in words(text1.lower()) for tag in text2.split())def cleaning(text, tags):return [tag for tag in tags if is_subset(text, tag)]def get_texts(self, text, max_len):texts = list(filter(lambda x : x != '', text.split('\n\n')))lengths = [len(tokenizer.encode(paragraph)) for paragraph in texts]output = []for i, par in enumerate(texts):index = len(output)if index > 0 and lengths[i] + len(tokenizer.encode(output[index-1])) <= max_len:output[index-1] = "".join(output[index-1] + par)else:output.append(par)return outputdef get_tags(self, text, generate_kwargs):input_text = 'summarize: ' + text.strip().replace('\n', ' ')tokenized_text = tokenizer.encode(input_text, return_tensors="pt")with torch.no_grad():tags_ids = model.generate(tokenized_text, **generate_kwargs)output = []for tags in tags_ids:cleaned = cleaning(text,list(set(tokenizer.decode(tags, skip_special_tokens=True).split(', '))))output.append(cleaned)return list(set(itertools.chain(*output)))def tag(self, text, max_len, generate_kwargs):texts = self.get_texts(text, max_len)all_tags = [self.get_tags(text, generate_kwargs) for text in texts]flatten_tags = itertools.chain(*all_tags)return list(set(flatten_tags))params = {"min_length": 0,"max_length": 30,"no_repeat_ngram_size": 2,"num_beams": 4,"early_stopping": True,"num_return_sequences": 4,}tags = tag(article, 512, params)print(tags)```### Overview- Model: T5 ([it5-small](https://huggingface.co/gsarti/it5-small))
README.md+74