Views
No views yet
T5ForConditionalGeneration(
(shared): Embedding(32100, 768)
(encoder): T5Stack(
(embed_tokens): Embedding(32100, 768)
(block): ModuleList(...)
(final_layer_norm): LayerNorm((768,), eps=1e-12)
(dropout): Dropout(p=0.1)
)
(decoder): T5Stack(
(embed_tokens): Embedding(32100, 768)
(block): ModuleList(...)
(final_layer_norm): LayerNorm((768,), eps=1e-12)
(dropout): Dropout(p=0.1)
)
(lm_head): Linear(in_features=768, out_features=32100, bias=False)
)
1pip install -U transformers torch datasets
2#Then, load the model and run inference:1model_name = "AventIQ-AI/t5_code_summarizer" # Update with your HF model ID
2tokenizer = RobertaTokenizer.from_pretrained(model_name)
3model = T5ForConditionalGeneration.from_pretrained(model_name)
4
5# Move to GPU if available
6device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
7model.to(device)
8
9# Inference
10code_snippet = "sum(d * 10 ** i for i, d in enumerate(x[::-1]))"
11inputs = tokenizer(code_snippet, max_length=128, truncation=True, padding="max_length", return_tensors="pt").to(device)
12outputs = model.generate(
13 input_ids=inputs["input_ids"],
14 attention_mask=inputs["attention_mask"],
15 max_length=128,
16 num_beams=4,
17 early_stopping=True
18)
19comment = tokenizer.decode(outputs[0], skip_special_tokens=True)
20print(f"Code: {code_snippet}")
21print(f"Comment: {comment}")
22# Expected output: Something close to "Concatenate elements of a list 'x' of multiple integers to a single integer"snippet:
Type: string
Min length: ~10 tokens
Mean length: ~20-30 tokens (estimated)
Max length: ~100 tokens (before truncation)
rewritten_intent:
Type: string
Min length: ~5 tokens
Mean length: ~10-15 tokens (estimated)
Max length: ~50 tokens (before truncation)
Samples:
snippet: sum(d * 10 ** i for i, d in enumerate(x[::-1])), rewritten_intent: "Concatenate elements of a list 'x' of multiple integers to a single integer"
snippet: int(''.join(map(str, x))), rewritten_intent: "Convert a list of integers into a single integer"
snippet: datetime.strptime('2010-11-13 10:33:54.227806', '%Y-%m-%d %H:%M:%S.%f'), rewritten_intent: "Convert a DateTime string back to a DateTime object of format '%Y-%m-%d %H:%M:%S.%f'"