AI3 - Phase 3
- Documentation available as web app, through
mkdocs. It can be run fromai3-hackathonrepository usingmkdocs serve.
Updated flow charts
The flowcharts can be found in the flowcharts section
File locations
Notebooks
- Notebooks created for data processing and mkodcs enabled:
MSI > /home/gqc/git/gqc/AI3/ai3-hackathon/docs/nbs - Notebooks used to train the LLMs and the saved LLMs:
MSI > /home/gqc/git/gqc/AI3 - Notebooks for YOLO:
MSI > ~/testing-yolo- Also has original and output videosWSL > /home/devengqc/git/projects/notebooks-from-colab/nbs
Data
- PSIAP IoT messages:
MSI > /home/gqc/git/gqc/AI3/ai3-hackathon/docs/data - AI3 PSIAP GDrive data:
WDBlack > /media/gqc/WD_BLACK1/ai3-new-data - NIST IoTData_EmergencyScenarios:
WDBlack > /media/gqc/WD_BLACK1/ai3-old-data - The saved files that contain LLAMA and OPT models' along with finetuned files are here:
MSI > /home/gqc/git/gqc/AI3
Notebooks - Functions
- We use
BeautifulSoupfor web scraping.- We have utils functions used in notebooks under
./iotgpt/
generate-sentences.ipynb- For a given JSON file, it generates sentences and saves as
./nbs/all-json-sentencified.csv. Functions used:iotgpt.mqtt.publisher.clean_obj, iotgpt.utils.generate_sentences_from_json
- For a given JSON file, it generates sentences and saves as
json-to-db.ipynb- This notebook will write all the sentences from JSON strings into a SQLite database
./questions-answers.db/q&a. - The table columns are - sentences, question, answers(default=None)
Functions used:from fastcore.utils import Path, globtastic- Note:
- There is no implementation to save to a DB.
- Looks like this was a work in-progress, to save the sentences data.
- This notebook will write all the sentences from JSON strings into a SQLite database
label.ipynb- For labelling the data with the help of Bard API, by reading sentences from
q&aDB. - It reads the data from tables, pings Bard API with 'hello' intially, checks for error responses, and then updates the answers column with the responses for questions in the DB.
Functions used:ask_bard function -> hasbardapi.core.Bard().get_answer(prompt)['content']
- For labelling the data with the help of Bard API, by reading sentences from
lookup-db.ipynb- This notebook creates the SQLiteDB structure from all the JSON files and the csv files.
- It gets a sorted list of keys, splits the keys on '_', gets the synonyms for each word in the key and generates combinations with the synonyms. It then saves data into table
ai3-lookup.dbas {keys, combined_keys} - It then connects to
ai3-lookup.dband saves the tables, phrase_synonyms and all_phrases_synonyms, into it. - We now find closest key based on
Levenshtein distanceonall_phrases_synonymstable and then finds parent key onphrase_synonyms. - This should also deal
NKkeys, but example isn't available. Functions used:iotgpt.utils, iotgpt.classification, generate_combinations, get_synonyms_thesaurus, Levenshtein.distance
merge-nb.ipynb- This notebook merges (concatenates) the outputs of the database containing labelled Bard outputs and GPT-3.5 outputs.
- Reads labelled-samples and 8000-samples csv files from
/nbswith questions and answers, and merges the files after renaming columns. Functions used:iotgpt.utils.generate_sentences_from_json
missing-keys.ipynb- Finds the closest sentence based on a key using levenstein distance.
- Has commented code for saving the keys as 'all-json-keys.pkl'
- It also finds missing keys.
Input: JSON data from 'PSIAP_AI3/'Output: List of Keys is saved as 'all-json-keys.pkl'Functions used:iotgpt.utils.{extract_keys, get_abbreviations, get_synonyms_thesaurus}, replace_word_with_underscore, find_missing_key
openai-exploration.ipynb- This notebook explores various prompts and models.
Functions used:OpenAI API
openllama-13b-instruct.ipynb- Has the Llama and transformers usage code.
- Looks like there are no successful runs yet, need to verify
Functions used:find_missing_key.{AutoModelForCausalLM, AutoTokenizer}, peft.{LoraConfig, TaskType, get_peft_model}
sample-for-training.ipynb- In this notebook, we create a sample of 2000 JSON sentences for training.
- Randomly selects json entries from
/Data, standardizes and sentencifies it, asks OpenAI models the questions for respective sentences and saves the answers. It also iterates over failed reponses to label missed JSON entries. Functions used:openai, fastcore.utils import Path, globtastic, coll_repr, iotgpt.utils.generate_sentences_from_json, standardize_keys
test.ipynb- This notebook creates the custom data structure from all the JSON files and the csv files.
- Saves abbreviations as a pickle file 'abbreviations-of-complex-keys-json-csv-3.pkl'
LLAMA2.ipynb- This is used for inferencing base LLAMA model from hugging face. Might have been for testing LLAMA usage in local.
finetune-LLAMA2.ipynb- This notebook is used for finetuning the base LLAMA model on custom data.
Notes
Data source : https://github.com/taugroup/PSIAP_AI3.git
- In MSI/AI3/ai3-hackathon, JSON data is available at '/PSIAP_AI3/Phase2/' and NK data is under '/PSIAP_AI3/Phase3/'.
- Additional data source (from notebooks) - AI3/docs/nbs
- ai3-lookup.db
Process:
- Receive the payload and convert it into a python dictionary object.
- Sentencify the dictionary object to get a sentencified JSON.
- Join sentences with a whitespace for Bard and the in-house model.
- Write the json payload to the sqlite database
- Notebooks
- Find missing keys
- This assumes missing keys will be '_' in JSON
- Extract keys from dictionary and join on ','.
- Use iotgpt.classification.find_missing_key to get missing keys, using Levenshtein distance on
all-json-keys.pkl. - If no missing keys found, proceed after notifying.
- Where is 'all-json-keys.pkl' - ai3-hackathon/search_dir
- Standardize and classsify
- We use the DB table with standard keys and synonyms to replace the JSON keys with standard keys.
- If no standard key found, we don't replace it and proceed.
- Sentencify
- Use Bard/GPT
- Use in house model
- Text to speech
- Find missing keys
Things to note :
While calculating the mean for the phrases and synonyms based on json values, we are ignoring strings because we can't find their mean. This means, we are also excluding the cases where strings have values like timestamps, dates etc.
One way to solve this is by converting dates to UNIX and for strings containing numbers to float/integers.
SK - It won't work because there is no distribution that we can use to understand the key for that value. It won't work unless we use LLMs like CHATGPT.
For eg:
if 2023-03-02T18:01:00.000Z is a value in a json, what would be it's key? Don't give explanations. Just give key value pair.
{
"timestamp": "2023-03-02T18:01:00.000Z"
}