decide
decide asks a bounded question about text and returns an answered, not-sure or failed result.
printf '%s' 'Please refund my order.' | thinkthen decide 'Does the customer request a refund?'Output
true
The simplest if
Section titled “The simplest if”A decide call with --check goes straight into an if. -q keeps the word off the screen, as with grep -q.
if thinkthen decide --check -q 'Does the customer request a refund?' \ --text 'Please refund my order.'; then echo "refund queue"fiThe then branch runs only on a yes. If the message could not be judged, the command exits 6 and says why on standard error. It never exits 0.
Don't add a plain else to this if. In a shell, else runs for every exit code that is not 0: no, not sure and failed alike. To act on a no, read the exit code:
status=0thinkthen decide --check -q 'Does the customer request a refund?' \ --text 'Please refund my order.' || status=$?
case $status in 0) echo "refund queue" ;; 1) echo "inbox" ;; *) exit "$status" ;;esacYes, no, or something else
Section titled “Yes, no, or something else”Send not sure to a person. Never treat it as a no.
Set two bars and decide can also be not sure. Exit codes 0 and 1 are the yes and the no. Codes 3 and 6 both mean there is no answer to read.
Handle every result state in Bash
status=0thinkthen decide --check -q 'Does the customer request a refund?' \ --text 'Where is my parcel?' --low 0.2 --high 0.8 || status=$?
case $status in 0) echo "refund queue" ;; 1) echo "inbox" ;; 3 | 6) echo "a person reads it" ;; *) exit "$status" ;;esac3 | 6 covers both not sure and failed. The last branch is for a mistake in the call itself, such as a misspelled option, which exits 2.
Not sure or failed
Section titled “Not sure or failed”Replace -q with --json to keep the result as well as the exit code.
status=0is_refund=$(thinkthen decide --check --json \ 'Does the customer request a refund?' \ --text 'Where is my parcel?' --low 0.2 --high 0.8) || status=$?
case $status in 3) echo "a person reads it" \ "$(jq -r '.probability' <<< "$is_refund")" ;; 6) echo "try again later" "$(jq -r '.error.code' <<< "$is_refund")" ;; 0) echo "refund queue" ;; 1) echo "inbox" ;; *) exit "$status" ;;esacYes and no are the two answers. Not sure and failed are the two ways of having none. Bash can't check that a case names every state, so end each one with a *) branch that stops the script.
The result's status field holds the same state as a word: answered, unsure or failed.
Did it work
Section titled “Did it work”Without --check, the exit code answers only "did it work". It is 0 for yes, no and not sure, and 6 when the result failed.
if ! is_refund=$(thinkthen decide \ 'Does the customer request a refund?' \ --text 'Please refund my order.'); then echo "could not judge it: $is_refund"fiWhen the service cannot judge the message, this reports the failure and its reason. Not sure counts as working: ThinkThen did its job, and the answer was "not sure".
Raise if it failed
Section titled “Raise if it failed”set -euo pipefail
is_refund=$(thinkthen decide 'Does the customer request a refund?' \ --text 'Please refund my order.')Under set -e this line stops the script at once when the result failed, with the command's exit code. Otherwise the script goes on, and $is_refund holds the printed word.
Both bars and the probability
Section titled “Both bars and the probability”thinkthen decide 'Does the customer request a refund?' \ --text 'Where is my parcel?' \ --low 0.2 --high 0.8 --json | jq '.probability'- No bar option: one bar at 0.5. The answer is always yes or no.
--threshold 0.7: one bar. Yes at 0.7 or above, otherwise no.--low 0.2 --high 0.8: two bars. No below 0.2, not sure from 0.2 up to 0.8, yes at 0.8 or above.
probability is the number ThinkThen compared with your bars: the model's probability of yes. A confident no has a low probability, such as 0.05. A result has no probability only when the result failed.
The number is the model's own. To choose bars for your data, run examples you have already labelled through thinkthen decide --json, save the results, and compare them with your labels using thinkthen audit, described at the end of this page.
Answer every CSV row
Section titled “Answer every CSV row”Read the CSV file and save its answers
--column selects the CSV column to judge; --into names the answer column. Check the exit status before using the saved file.
messagePlease refund my order.thinkthen decide 'Does the customer request a refund?' messages.csv \ --column message --into is_refundcat messages.thinkthen.csvOutput
messages.thinkthen.csv
message,is_refund
Please refund my order.,TRUE
See why
Section titled “See why”Read the model’s numbers with the answer state
The state distinguishes an answer from not sure and failure. These are the actual numbers returned for the shown message.
echo 'I was charged twice for one invoice.' | thinkthen decide --low 0.2 --high 0.8 --json \ 'Does the customer request a refund?' | jq -c '{status, probability}'Output
{"status":"unsure","probability":0.71}
Options
Section titled “Options”Options
| Option | What it does |
|---|---|
<QUESTION> | Question to ask |
[FILE]... | Input files; default: standard input |
--name <NAME> | Optional execution identity |
--text <TEXT> | Judge this text instead of reading input |
--threshold <THRESHOLD> | Required probability |
--low <LOW> | Low probability bar |
--high <HIGH> | High probability bar |
--check [=<CHECK>] | Return the verdict as an exit code |
--yes-means <TEXT> | Meaning of a true answer |
--no-means <TEXT> | Meaning of a false answer |
--column <COLUMN> | Field column; repeat; replaces a saved pointer |
--details [=<DETAILS>] | Add status, probability, error, detail and source columns |
--in-place [=<IN-PLACE>] | Replace source with backup |
--into <INTO> | Answer field for JSON Lines; column for tables |
--output <OUTPUT> | Destination path |
--sheet <SHEET> | Worksheet |