File size: 3,189 Bytes
6dcd428
 
9dded33
 
 
 
8357034
67be776
 
 
 
 
 
bcf652b
 
 
 
 
 
 
 
9dded33
 
a8dd195
 
 
 
67be776
d248fe1
ba7bbbc
d248fe1
ba7bbbc
7ec0e4f
d248fe1
 
ba7bbbc
7ec0e4f
ba7bbbc
 
 
 
 
 
 
 
 
 
 
 
 
7ec0e4f
c0f6805
ba7bbbc
 
 
7ec0e4f
ba7bbbc
e2fbb96
c0f6805
e2fbb96
 
 
 
 
ba7bbbc
e2fbb96
ba7bbbc
 
 
 
c0f6805
 
 
 
 
ba7bbbc
 
 
c0f6805
7ec0e4f
 
 
 
 
 
cdde43e
e2fbb96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
license: mit
datasets:
- Vezora/Tested-143k-Python-Alpaca
language:
- en
widget:
- example_title: Python!
  messages:
  - role: system
    content: based on given instruction create a solution
  - role: user
    content: here are the instruction write a function that add two list
  output:
      text: >-
        Arr! 'Tis a puzzlin' matter, me hearty! A llama on yer lawn be a rare
        sight, but I've got a plan that might help ye get rid of 'im. Ye'll need
        to gather some carrots and hay, and then lure the llama away with the
        promise of a tasty treat. Once he's gone, ye can clean up yer lawn and
        enjoy the peace and quiet once again. But beware, me hearty, for there
        may be more llamas where that one came from! Arr!
tags:
- code
inference:
  parameters:
    max_new_tokens: 100
    do_sample: false
pipeline_tag: text-generation
---
# Gemma-2B Fine-Tuned Python Model

## Overview
Gemma-2B Fine-Tuned Python Model is a deep learning model based on the Gemma-2B architecture, fine-tuned specifically for Python programming tasks. This model is designed to understand Python code and assist developers by providing suggestions, completing code snippets, or offering corrections to improve code quality and efficiency.

## Model Details
- **Model Name**: Gemma-2B Fine-Tuned Python Model
- **Model Type**: Deep Learning Model
- **Base Model**: Gemma-2B
- **Language**: Python
- **Task**: Python Code Understanding and Assistance

## Example Use Cases
- Code completion: Automatically completing code snippets based on partial inputs.
- Syntax correction: Identifying and suggesting corrections for syntax errors in Python code.
- Code quality improvement: Providing suggestions to enhance code readability, efficiency, and maintainability.
- Debugging assistance: Offering insights and suggestions to debug Python code by identifying potential errors or inefficiencies.

## How to Use
1. **Install Gemma Python Package**:
   ```bash
    pip install -q -U transformers==4.38.0
    pip install torch
   ```

## Inference
1. **How to use the model in our notebook**:
```python
# Load model directly
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("suriya7/Gemma-2B-Finetuned-Python-Model")
model = AutoModelForCausalLM.from_pretrained("suriya7/Gemma-2B-Finetuned-Python-Model")

query = input('enter a query:')
prompt_template = f"""
<start_of_turn>user based on given instruction create a solution\n\nhere are the instruction {query}
<end_of_turn>\n<start_of_turn>model
"""
prompt = prompt_template
encodeds = tokenizer(prompt, return_tensors="pt", add_special_tokens=True).input_ids

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model.to(device)
inputs = encodeds.to(device)


# Increase max_new_tokens if needed
generated_ids = model.generate(inputs, max_new_tokens=1000, do_sample=False, pad_token_id=tokenizer.eos_token_id)
ans = ''
for i in tokenizer.decode(generated_ids[0], skip_special_tokens=True).split('<end_of_turn>')[:2]:
    ans += i

# Extract only the model's answer
model_answer = ans.split("model")[1].strip()
print(model_answer)
```