File size: 1,422 Bytes
7f51a5a
cb23e9a
7f51a5a
 
 
 
 
 
2856ccc
7f51a5a
 
85c4439
b7b2ce3
9b2bdb3
 
f100939
9b2bdb3
f100939
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig, TrainingArguments, Trainer
import torch
import time
import evaluate
import pandas as pd
import numpy as np

import streamlit as st
st.title('Code Generation')
huggingface_dataset_name = "red1xe/code_instructions"
dataset = load_dataset(huggingface_dataset_name)
model_name='gpt2'
tokenizer = AutoTokenizer.from_pretrained("bigcode/starcoder")
original_model = AutoModelForCausalLM.from_pretrained("bigcode/starcoder")

x = st.slider(label='Select a sample', min_value=0, max_value=1000, value=500, step=10)
if st.button("Show Sample"):
    index = x

    input = dataset['test'][index]['input']
    instruction = dataset['test'][index]['instruction']
    output = dataset['test'][index]['output']

    prompt = f"""
    Answer the following question.

    {input} {instruction}

    Answer:
    """

    inputs = tokenizer(prompt, return_tensors='pt')
    outputs = tokenizer.decode(
        original_model.generate(
            inputs["input_ids"],
            max_new_tokens=200,
        )[0],
        skip_special_tokens=True
    )

    dash_line = '-'.join('' for x in range(100))
    st.write(dash_line)
    st.write(f'INPUT PROMPT:\n{prompt}')
    st.write(dash_line)
    st.write(f'BASELINE HUMAN SUMMARY:\n{output}\n')
    st.write(dash_line)
    st.write(f'MODEL GENERATION - ZERO SHOT:\n{outputs}')