PLatonG commited on
Commit
2b123f0
1 Parent(s): 02d6c43

Upload 4 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ FILTER_GREATERTHANTHREE_FROM_SHEETS_SMOTE_train.csv filter=lfs diff=lfs merge=lfs -text
Callback.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Helpers to support streaming generate output.
3
+ Borrowed from https://github.com/oobabooga/text-generation-webui/blob/ad37f396fc8bcbab90e11ecf17c56c97bfbd4a9c/modules/callbacks.py
4
+ """
5
+
6
+ import gc
7
+ import traceback
8
+ from queue import Queue
9
+ from threading import Thread
10
+
11
+ import torch
12
+ import transformers
13
+
14
+
15
+ class Stream(transformers.StoppingCriteria):
16
+ def __init__(self, callback_func=None):
17
+ self.callback_func = callback_func
18
+
19
+ def __call__(self, input_ids, scores) -> bool:
20
+ if self.callback_func is not None:
21
+ self.callback_func(input_ids[0])
22
+ return False
23
+
24
+
25
+ class Iteratorize:
26
+
27
+ """
28
+ Transforms a function that takes a callback
29
+ into a lazy iterator (generator).
30
+ """
31
+
32
+ def __init__(self, func, kwargs={}, callback=None):
33
+ self.mfunc = func
34
+ self.c_callback = callback
35
+ self.q = Queue()
36
+ self.sentinel = object()
37
+ self.kwargs = kwargs
38
+ self.stop_now = False
39
+
40
+ def _callback(val):
41
+ if self.stop_now:
42
+ raise ValueError
43
+ self.q.put(val)
44
+
45
+ def gentask():
46
+ try:
47
+ ret = self.mfunc(callback=_callback, **self.kwargs)
48
+ except ValueError:
49
+ pass
50
+ except:
51
+ traceback.print_exc()
52
+ pass
53
+
54
+ self.q.put(self.sentinel)
55
+ if self.c_callback:
56
+ self.c_callback(ret)
57
+
58
+ self.thread = Thread(target=gentask)
59
+ self.thread.start()
60
+
61
+ def __iter__(self):
62
+ return self
63
+
64
+ def __next__(self):
65
+ obj = self.q.get(True, None)
66
+ if obj is self.sentinel:
67
+ raise StopIteration
68
+ else:
69
+ return obj
70
+
71
+ def __enter__(self):
72
+ return self
73
+
74
+ def __exit__(self, exc_type, exc_val, exc_tb):
75
+ self.stop_now = True
FILTER_GREATERTHANTHREE_FROM_SHEETS_SMOTE_train.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fe0b99be053bfc84bbe4afcc05fe39f90c149427c14fa5551d2b3505a80a443e
3
+ size 24859949
Prompter.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os.path as osp
3
+ from typing import Union
4
+ class Prompter(object):
5
+ __slots__ = ("template", "_verbose")
6
+
7
+ def __init__(self, template_name: str = "", verbose: bool = False):
8
+ self._verbose = verbose
9
+ if not template_name:
10
+ # Enforce the default here, so the constructor can be called with '' and will not break.
11
+ template_name = "alpaca"
12
+ file_name = osp.join("templates", f"{template_name}.json")
13
+ if not osp.exists(file_name):
14
+ raise ValueError(f"Can't read {file_name}")
15
+ with open(file_name) as fp:
16
+ self.template = json.load(fp)
17
+ if self._verbose:
18
+ print(
19
+ f"Using prompt template {template_name}: {self.template['description']}"
20
+ )
21
+
22
+ def generate_prompt(
23
+ self,
24
+ instruction: str,
25
+ input: Union[None, str] = None,
26
+ label: Union[None, str] = None,
27
+ ) -> str:
28
+ # returns the full prompt from instruction and optional input
29
+ # if a label (=response, =output) is provided, it's also appended.
30
+ if input:
31
+ res = self.template["prompt_input"].format(
32
+ instruction=instruction, input=input
33
+ )
34
+ else:
35
+ res = self.template["prompt_no_input"].format(
36
+ instruction=instruction
37
+ )
38
+ if label:
39
+ res = f"{res}{label}"
40
+ if self._verbose:
41
+ print(res)
42
+ return res
43
+
44
+ def get_response(self, output: str) -> str:
45
+ return output.split(self.template["response_split"])[1].strip()
templates/alpaca.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "description": "Template used by Alpaca-LoRA.",
3
+ "prompt_input": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Input:\n{input}\n\n### Response:\n",
4
+ "prompt_no_input": "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Response:\n",
5
+ "response_split": "### Response:"
6
+ }