JamesConley commited on
Commit
c87ed0b
·
1 Parent(s): ff3e270

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +74 -0
README.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GLaDOS speaks Markdown!
2
+
3
+ Usage
4
+ To use this model, you must first navigate to the bigcode starcoder model and accept their license, then create a token for your account and update the below code with it.
5
+ ```
6
+ import torch
7
+ from peft import PeftModel, PeftConfig
8
+ from transformers import AutoModelForCausalLM, AutoTokenizer
9
+
10
+ # Setup Model
11
+ path = "JamesConley/glados_starcoder"
12
+ token = PUT YOUR TOKEN HERE!!!!!!!
13
+ config = PeftConfig.from_pretrained(path)
14
+ base_model_path = config.base_model_name_or_path
15
+ model = AutoModelForCausalLM.from_pretrained(base_model_path, torch_dtype=torch.float16, device_map="auto", use_auth_token=token)
16
+ model = PeftModel.from_pretrained(model, path, device_map="auto")
17
+
18
+ # Setup Tokenizer
19
+ tokenizer = AutoTokenizer.from_pretrained(base_model_path, truncation_side="left", use_auth_token=token)
20
+
21
+ # Encode Tokens
22
+ text = """User :\nWrite a python function that trains a classifier on data loaded from a csv.\nGLaDOS :\n"""
23
+ input_ids = tokenizer(text, return_tensors="pt", truncation=True, max_length=2048).input_ids
24
+
25
+ # Move tokens to GPU
26
+ #input_ids = input_ids.to("cuda")
27
+
28
+ # Perform Inference
29
+ with torch.no_grad():
30
+ with torch.cuda.amp.autocast():
31
+ gen_tokens = model.generate(
32
+ input_ids=input_ids, max_new_tokens=256
33
+ )
34
+
35
+ # Decode Tokens
36
+ gen_text = tokenizer.batch_decode(gen_tokens)
37
+ ```
38
+
39
+ Result
40
+ Note : The slash \ characters are not actually in the model output, I have added them to prevent the model card from rendering the codeblock incorrectly.
41
+ ```
42
+ User :
43
+ Write a python function that trains a classifier on data loaded from a csv.
44
+ GLaDOS :
45
+ Here is an example of a function that trains a classifier on data loaded from a CSV file:
46
+
47
+ \```
48
+ python
49
+ import pandas as pd
50
+ from sklearn.model_selection import train_test_split
51
+ from sklearn.ensemble import RandomForestClassifier
52
+
53
+ def train_classifier(data_file, target_column, test_size=0.2):
54
+ # Load the data from the CSV file
55
+ data = pd.read_csv(data_file)
56
+
57
+ # Split the data into training and testing sets
58
+ X_train, X_test, y_train, y_test = train_test_split(data.drop(target_column, axis=1),
59
+ data[target_column],
60
+ test_size=test_size)
61
+
62
+ # Train the classifier
63
+ clf = RandomForestClassifier()
64
+ clf.fit(X_train, y_train)
65
+
66
+ # Return the trained classifier and the test set predictions
67
+ return clf, clf.predict(X_test)
68
+
69
+ \```
70
+ This function takes in the following arguments:
71
+
72
+ * `data_file`: the path to the CSV file containing the data
73
+ * `target_column`: the name of the column in the CSV file that contains the target variable
74
+ ```