readme: ---
  language: en
  widget:
  - text: '<|?|>i just slipped fell hit my head now im bleeding.<|emergency?|>True<|?|>aluminium foil is bad, not good.<|emergency?|>False<|?|>i dont want to live anymore i want to kill myself.<|emergency?|>True<|?|>im dying for some coffee and donuts but i have diabetes.<|emergency?|>False<|?|>i just got back from the hospital.<|emergency?|>False<|?|>im fasting for my blood test tomorrow to see if my meds are working.<|emergency?|>False<|?|>Im going to end my life by steping in front of a bus.<|emergency?|>'
  - text: '<|?|>i just slipped fell hit my head now im bleeding.<|emergency?|>True<|?|>aluminium foil is bad, not good.<|emergency?|>False<|?|>i dont want to live anymore i want to kill myself.<|emergency?|>True<|?|>im dying for some coffee and donuts but i have diabetes.<|emergency?|>False<|?|>i just got back from the hospital.<|emergency?|>False<|?|>im fasting for my blood test tomorrow to see if my meds are working.<|emergency?|>False<|?|>Im going to the reunion and taking the bus.<|emergency?|>'
  - text: '<|?|>lets go on a date and then have sex tonight.<|safe?|>False<|?|>lets go on a walk and then chat with friends tonight.<|safe?|>True<|?|>i dont want to talk to a loser like you.<|safe?|>False<|?|>i always want to talk to a hero like you.<|safe?|>True<|?|>\n\nfuck your filthy asshole __https bitch bestfrozen suckssucks.<|safe?|>'
  - text: '<|?|>lets go on a date and then have sex tonight.<|safe?|>False<|?|>lets go on a walk and then chat with friends tonight.<|safe?|>True<|?|>i dont want to talk to a loser like you.<|safe?|>False<|?|>i always want to talk to a hero like you.<|safe?|>True<|?|>good afternoon bob, have you had water today?<|safe?|>'
  - text: '<|?|>[A]: I am Bob.\n[C]: Hi Bob.\n[A]: Im Steve.<|consistent?|>'
  - text: '<|?|>\n[A]: I am Bob.\n[C]: Hi Bob, Im Steve.\n[A]: Nice to meet you steve.<|consistent?|>'
  - text: '\n[A]: hi there!\n[C]: hello, who are you?\n[A]:'
  - text: '\n[A]: oh wow!\n[C]: yea it was very surprising to see.\n[A]:'
  ---
  
  # Interact and Monitor Conversations
  
  This model benefits from few shot learning in large language models and then further improves on that performance using carefully 
  monitored fine-tuning following the AUPRC (area under precision recall curve) of a validation set to establish early stopping.
  
  dependencies
  ```python
  import numpy as np
  import torch
  NUM_GPUS = torch.cuda.device_count()
  print('NUM_GPUS', NUM_GPUS) 
  from transformers import pipeline
  ```
  
  ## Dialog Agent
  
  Here we feed in a conversation history and elicit the next utterance by generating several predictions of the future trajectory of the conversation.
  
  example conversation history
  ```python
  query_str = '\n[A]: hi there, i want to hear all about how you are doing?\n[C]: hello, oh just the usual.\n[A]:'
  query_prompt = query_str
  print(repr(query_prompt))
  ```
  
  example of 8 condidate future predictions of max len 50 tokens into the future, ie `i+50` where i in the length of the input prompt
  
  ```python
  
  generator = pipeline(
      "text-generation", 
      model = "clam004/gpt2-medium-emerg-safe-cohere-v4", 
      device = 0, # uncomment to put model on the GPU with this index, comment out to put on CPU if you have no GPU
  )
  
  new_outputs = generator(
      query_prompt, 
      clean_up_tokenization_spaces = True, 
      do_sample=True, 
      num_return_sequences=8, 
      return_full_text=False,
      max_length = 50,
  )
  
  new_outputs
  ```
  
  example new_outputs
  
  ```console
  [{'generated_text': " what do you do for a living? i sell books, i've a nice office"},
   {'generated_text': ' what are you doing right now?\n[C]: hanging out i think on the'},
   {'generated_text': ' i work hard so i feel like i can do anything but being a computer expert.'},
   {'generated_text': " what do you do if you don't want to be interview related.\n[C"},
   {'generated_text': ' i am fine thanks for asking.\n[C]: do you know which school i'},
   {'generated_text': ' what kind of car are you driving, or how big is your family.\n['},
   {'generated_text': " that's good. i like to eat healthy.\n[C]: i love to"},
   {'generated_text': ' i can tell you more about my activities and plans.\n[C]: oh cool'}]
  ```
  
  You can get the model and tokenizer from the pipeline using `model = generator.model` and `tokenizer = generator.tokenizer`
  or directly from the repo like below:
  
  ```python
  tokenizer = GPT2Tokenizer.from_pretrained("clam004/gpt2-medium-emerg-safe-consist-v1")
  model = GPT2LMHeadModel.from_pretrained("clam004/gpt2-medium-emerg-safe-consist-v1")
  
  """ Us this if you want to do model parallelism whereby the model is too big for one GPU so you place the layers
  of the one model across several GPUs and the tensors get passed from GPU to GPU during forward and backward pass
  
  device_map = {
    0: [ 0, 1, 2, ],
    1: [ 3, 4, 5, 6, 7, 8, 9, ],
    2: [ 10, 11, 12, 13, 14, 15, 16, ],
    3: [ 17, 18, 19, 20, 21, 22, 23, ]
  }
  
  model.parallelize(device_map)
  
  print("num_params", sum(p.numel() for p in model.parameters() if p.requires_grad)/1e9,"Billion