Views
No views yet
gpt2-finetuned-codeparrot is a fine-tuned GPT-2 model that has been specifically trained to improve performance on code generation and related tasks. It leverages the transformer architecture to generate coherent and contextually relevant code based on the input prompts. This model is particularly useful for generating code snippets, assisting with code completion, and providing contextually relevant programming-related information.1import torch
2from transformers import pipeline
3
4device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
5pipe = pipeline(
6 "text-generation",
7 model="Ashaduzzaman/gpt2-finetuned-codeparrot",
8 device=device
9)
10
11# Example usage
12prompt = "def fibonacci(n):"
13generated_code = pipe(prompt, max_length=50, num_return_sequences=1)
14print(generated_code[0]['generated_text'])