lawrencewu commited on
Commit
e4a1707
1 Parent(s): e586316

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +58 -0
README.md CHANGED
@@ -10,6 +10,64 @@ model-index:
10
  results: []
11
  ---
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
14
  should probably proofread and complete it, then remove this comment. -->
15
 
 
10
  results: []
11
  ---
12
 
13
+ # Usage
14
+
15
+ You can use this model with the following code:
16
+
17
+ First, download the model
18
+
19
+ ```python
20
+ from peft import AutoPeftModelForCausalLM
21
+ from transformers import AutoTokenizer
22
+ model_id='lawrencewu/hc-mistral-7B-v0.3-alpaca-first-100'
23
+ model = AutoPeftModelForCausalLM.from_pretrained(model_id).cuda()
24
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
25
+ tokenizer.pad_token = tokenizer.eos_token
26
+ ```
27
+
28
+ Then, construct the prompt template like so:
29
+
30
+ ```python
31
+ def prompt(nlq, cols):
32
+ return f"""Honeycomb is an observability platform that allows you to write queries to inspect trace data. You are an assistant that takes a natural language query (NLQ) and a list of valid columns and produce a Honeycomb query.
33
+
34
+ ### Instruction:
35
+
36
+ NLQ: "{nlq}"
37
+
38
+ Columns: {cols}
39
+
40
+ ### Response:
41
+ """
42
+
43
+ def prompt_tok(nlq, cols):
44
+ _p = prompt(nlq, cols)
45
+ input_ids = tokenizer(_p, return_tensors="pt", truncation=True).input_ids.cuda()
46
+ out_ids = model.generate(input_ids=input_ids, max_new_tokens=5000,
47
+ do_sample=False)
48
+ return tokenizer.batch_decode(out_ids.detach().cpu().numpy(),
49
+ skip_special_tokens=True)[0][len(_p):]
50
+ ```
51
+
52
+ Finally, you can get predictions like this:
53
+
54
+ ```python
55
+ # model inputs
56
+ nlq = "Exception count by exception and caller"
57
+ cols = ['error', 'exception.message', 'exception.type', 'exception.stacktrace', 'SampleRate', 'name', 'db.user', 'type', 'duration_ms', 'db.name', 'service.name', 'http.method', 'db.system', 'status_code', 'db.operation', 'library.name', 'process.pid', 'net.transport', 'messaging.system', 'rpc.system', 'http.target', 'db.statement', 'library.version', 'status_message', 'parent_name', 'aws.region', 'process.command', 'rpc.method', 'span.kind', 'serializer.name', 'net.peer.name', 'rpc.service', 'http.scheme', 'process.runtime.name', 'serializer.format', 'serializer.renderer', 'net.peer.port', 'process.runtime.version', 'http.status_code', 'telemetry.sdk.language', 'trace.parent_id', 'process.runtime.description', 'span.num_events', 'messaging.destination', 'net.peer.ip', 'trace.trace_id', 'telemetry.instrumentation_library', 'trace.span_id', 'span.num_links', 'meta.signal_type', 'http.route']
58
+
59
+ # print prediction
60
+ out = prompt_tok(nlq, cols)
61
+ print(nlq, '\n', out)
62
+ ```
63
+
64
+ This will give you a prediction that looks like this:
65
+
66
+ ```md
67
+ "{'breakdowns': ['exception.message', 'exception.type'], 'calculations': [{'op': 'COUNT'}], 'filters': [{'column': 'exception.message', 'op': 'exists'}, {'column': 'exception.type', 'op': 'exists'}], 'orders': [{'op': 'COUNT', 'order': 'descending'}], 'time_range': 7200}"
68
+ ```
69
+
70
+
71
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
72
  should probably proofread and complete it, then remove this comment. -->
73