Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Move models to txtinstruct project

davidmezzettiaa07d4c010d1
diff --git a/models/bashsql/generate.py b/models/bashsql/generate.py
deleted file mode 100644
index c9104d8c..00000000
--- a/models/bashsql/generate.py
+++ /dev/null
@@ -1,104 +0,0 @@
-"""
-Generate bashsql training data
-"""
-
-import random
-import sys
-
-
-def write(output, query, sql):
- """
- Write query-sql pair to to output.
-
- Args:
- output: output file
- query: source query
- sql: target sql
- """
-
- output.write(f'"{query}","{sql}"\n')
-
-
-def run(outfile):
- """
- Generates bashsql data.
-
- Args:
- outfile: output file path
- """
-
- with open("../queries.txt", "r", encoding="utf-8") as queries:
- with open(outfile, "w", encoding="utf-8") as output:
- output.write("source,target\n")
- for query in queries:
- query = query.lower().strip().replace('"', '""')
- find = f'find -name ""{query}""' if " " in query else f"find -name {query}"
- sql = f"select id, text, score from txtai where similar('{query}')"
-
- # Standard query
- write(output, find, sql)
-
- # Query by date
- write(output, f"{find} -mtime -1", f"{sql} and entry >= date('now', '-1 day')")
- write(output, f"{find} -mtime -1.5", f"{sql} and entry >= date('now', '-1.5 day')")
- write(output, f"{find} -mtime -2", f"{sql} and entry >= date('now', '-2 day')")
-
- # Query by score (t5 models map < to unk token, use $= as workaround)
- write(output, f"{find} -score +0.5", f"{sql} and score >= 0.5")
- write(output, f"{find} -score -0.7", f"{sql} and score $= 0.7")
-
- # Query by date and score
- write(output, f"{find} -mtime -1 -score -0.5", f"{sql} and entry >= date('now', '-1 day') and score $= 0.5")
- write(output, f"{find} -score +0.2 -mtime -1", f"{sql} and score >= 0.2 and entry >= date('now', '-1 day')")
-
- # Query by text field
- write(output, f"{find} -field value", f"{sql} and field = 'value'")
- write(output, f'{find} -field "multi value"', f"{sql} and field = 'multi value'")
-
- # Query by numeric field
- write(output, f"{find} -quantity 1", f"{sql} and quantity = 1")
- write(output, f"{find} -quantity +50", f"{sql} and quantity >= 50")
- write(output, f"{find} -quantity -50", f"{sql} and quantity $= 50")
-
- # Query with contains
- write(output, f"{find} -text ~data", f"{sql} and text like '%data%'")
- write(output, f"{find} -field ~value", f"{sql} and field like '%value%'")
- write(output, f"{find} -text ~snippet", f"{sql} and text like '%snippet%'")
-
- # Aggregates
- write(output, f"{find} -count", f"select count(*) from txtai where similar('{query}')")
- write(output, f"{find} -average", f"select avg(score) from txtai where similar('{query}')")
-
- # Translate
- lang = ["ar", "en", "fr", "de", "hi", "it", "nl", "ro", "ru", "zh"]
- lang1, lang2 = random.choice(lang), random.choice(lang)
- write(output, f"{find} -translate {lang1}", f"select id, translate(text, '{lang1}') text, score from txtai where similar('{query}')")
- write(output, f"{find} -translate {lang2}", f"select id, translate(text, '{lang2}') text, score from txtai where similar('{query}')")
- write(
- output,
- f"{find} -mtime -1 -field 0 -translate {lang1}",
- f"select id, translate(text, '{lang1}') text, score from txtai where similar('{query}') "
- + "and entry >= ('now', '-1 day') and field = 0",
- )
-
- # Summary
- write(output, f"{find} -summary", f"select id, summary(text) text, score from txtai where similar('{query}')")
- write(
- output,
- f"{find} -mtime -1 -summary",
- f"select id, summary(text) text, score from txtai where similar('{query}') and entry >= date('now', '-1 day')",
- )
-
- # Limit
- write(output, f"{find} -limit 1", f"{sql} limit 1")
- write(
- output,
- f"{find} -limit 5 -summary",
- f"select id, summary(text) text, score from txtai where similar('{query}') and entry >= date('now', '-1 day') limit 5",
- )
-
-
-if __name__ == "__main__":
- # Set seed (to generate consistent output) and run
- random.seed(1024)
- run(sys.argv[1])
diff --git a/models/bashsql/train.py b/models/bashsql/train.py
deleted file mode 100644
index 5ca22641..00000000
--- a/models/bashsql/train.py
+++ /dev/null
@@ -1,37 +0,0 @@
-"""
-Train a bashsql model
-"""
-
-import sys
-
-import pandas as pd
-
-from txtai.pipeline import HFTrainer
-
-
-def run(data, output):
- """
- Trains a txtsql model.
-
- Args:
- data: path to input data file
- output: model output path
- """
-
- train = HFTrainer()
- train(
- "t5-small",
- pd.read_csv(data),
- task="sequence-sequence",
- prefix="translate Bash to SQL: ",
- maxlength=512,
- per_device_train_batch_size=4,
- num_train_epochs=5,
- output_dir=output,
- overwrite_output_dir=True,
- )
-
-
-if __name__ == "__main__":
- # Run train loop
- run(sys.argv[1], sys.argv[2])
diff --git a/models/queries.txt b/models/queries.txt
deleted file mode 100644
index 03432927..00000000
--- a/models/queries.txt
+++ /dev/null
@@ -1,50 +0,0 @@
-africa
-antarctica
-apple sales report
-arts and culture
-asia
-australia
-birds
-books
-breaking news
-business and finance
-car drive
-climate change
-computers
-comedy
-eating having fun
-education
-entertainment
-europe
-family
-fashion
-feel good story
-football scores
-fun and leisure
-lucky
-market news
-music news
-north america
-oil prices
-operating systems
-phone call
-photo editing
-politics
-public health story
-red socks with shoes
-science
-social media
-society
-software development
-south america
-stock quotes
-stories about crime
-tech news
-tell me something good
-top news stories
-top sports stories
-usb device drivers
-vacation
-war
-weather forecast
-wildlife
\ No newline at end of file
diff --git a/models/txtsql/generate.py b/models/txtsql/generate.py
deleted file mode 100644
index 66d83a9f..00000000
--- a/models/txtsql/generate.py
+++ /dev/null
@@ -1,109 +0,0 @@
-"""
-Generate txtsql training data
-"""
-
-import random
-import sys
-
-
-def write(output, query, sql):
- """
- Write query-sql pair to to output.
-
- Args:
- output: output file
- query: source query
- sql: target sql
- """
-
- output.write(f'"{query}","{sql}"\n')
-
-
-def run(outfile):
- """
- Generates txtsql data.
-
- Args:
- outfile: output file path
- """
-
- with open("../queries.txt", "r", encoding="utf-8") as queries:
- with open(outfile, "w", encoding="utf-8") as output:
- output.write("source,target\n")
- for query in queries:
- query = query.lower().strip().replace('"', '""')
- sql = f"select id, text, score from txtai where similar('{query}')"
-
- # Standard query
- write(output, query, sql)
-
- # Query by date
- write(output, f"{query} since yesterday", f"{sql} and entry >= date('now', '-1 day')")
- write(output, f"{query} since 36 hours ago", f"{sql} and entry >= date('now', '-36 hour')")
- write(output, f"{query} over last 2 days", f"{sql} and entry >= date('now', '-2 day')")
- write(output, f"{query} since 2 days ago", f"{sql} and entry >= date('now', '-2 day')")
- write(output, f"{query} since 7 days ago", f"{sql} and entry >= date('now', '-7 day')")
- write(output, f"{query} since 2 months ago", f"{sql} and entry >= date('now', '-2 month')")
-
- # Query by score (t5 models map < to unk token, use $= as workaround)
- write(output, f"{query} with score greater than 0.5", f"{sql} and score >= 0.5")
- write(output, f"{query} with score less than 0.7", f"{sql} and score $= 0.7")
-
- # Query by date and score
- write(output, f"{query} since yesterday and score less than 0.5", f"{sql} and entry >= date('now', '-1 day') and score $= 0.5")
- write(output, f"{query} with a score greater than 0.2 since yesterday", f"{sql} and score >= 0.2 and entry >= date('now', '-1 day')")
-
- # Query by text field
- write(output, f"{query} with field equal to value", f"{sql} and field = 'value'")
- write(output, f"{query} with field equal to multi value", f"{sql} and field = 'multi value'")
-
- # Query by numeric field
- write(output, f"{query} with quantity equal to 1", f"{sql} and quantity = 1")
- write(output, f"{query} with quantity greater than 50", f"{sql} and quantity >= 50")
- write(output, f"{query} with quantity less than 50", f"{sql} and quantity $= 50")
-
- # Query with OR
- write(output, f"{query} having text equal data or field as snippet", f"{sql} and (text = 'data' or field = 'snippet')")
- write(output, f"{query} having text as data or field equal snippet value", f"{sql} and (text = 'data' or field = 'snippet value')")
- write(output, f"{query} with field equal snippet or text as data", f"{sql} and (field = 'snippet' or text = 'data')")
-
- # Query with contains
- write(output, f"{query} with data in text", f"{sql} and text like '%data%'")
- write(output, f"{query} with value in field", f"{sql} and field like '%value%'")
- write(output, f"{query} with snippet in text", f"{sql} and text like '%snippet%'")
-
- # Aggregates
- write(output, f"how many results are {query}", f"select count(*) from txtai where similar('{query}')")
- write(output, f"average score for {query}", f"select avg(score) from txtai where similar('{query}')")
-
- # Translate
- lang = ["ar", "en", "fr", "de", "hi", "it", "nl", "ro", "ru", "zh"]
- lang1, lang2 = random.choice(lang), random.choice(lang)
- write(
- output, f"{query} translated to {lang1}", f"select id, translate(text, '{lang1}') text, score from txtai where similar('{query}')"
- )
- write(
- output, f"{query} translated to {lang2}", f"select id, translate(text, '{lang2}') text, score from txtai where similar('{query}')"
- )
-
- # Summary
- write(output, f"{query} summarized", f"select id, summary(text) text, score from txtai where similar('{query}')")
- write(
- output,
- f"{query} since yesterday summarized",
- f"select id, summary(text) text, score from txtai where similar('{query}') and entry >= date('now', '-1 day')",
- )
-
- # Limit
- write(output, f"{query} limit to 1", f"{sql} limit 1")
- write(
- output,
- f"{query} limit to 5 summarized",
- f"select id, summary(text) text, score from txtai where similar('{query}') and entry >= date('now', '-1 day') limit 5",
- )
-
-
-if __name__ == "__main__":
- # Set seed (to generate consistent output) and run
- random.seed(1024)
- run(sys.argv[1])
diff --git a/models/txtsql/train.py b/models/txtsql/train.py
deleted file mode 100644
index db98f1e2..00000000
--- a/models/txtsql/train.py
+++ /dev/null
@@ -1,37 +0,0 @@
-"""
-Train a txtsql model
-"""
-
-import sys
-
-import pandas as pd
-
-from txtai.pipeline import HFTrainer
-
-
-def run(data, output):
- """
- Trains a txtsql model.
-
- Args:
- data: path to input data file
- output: model output path
- """
-
- train = HFTrainer()
- train(
- "t5-small",
- pd.read_csv(data),
- task="sequence-sequence",
- prefix="translate English to SQL: ",
- maxlength=512,
- per_device_train_batch_size=4,
- num_train_epochs=5,
- output_dir=output,
- overwrite_output_dir=True,
- )
-
-
-if __name__ == "__main__":
- # Run train loop
- run(sys.argv[1], sys.argv[2])