File size: 1,649 Bytes
e2a3f6a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import joblib
import pandas as pd
from sklearn.metrics.pairwise import cosine_similarity
from sklearn.feature_extraction.text import TfidfVectorizer
import argparse
def main():
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--input', type=str, help="Input file path (file should be in parquet format and have 'prompt' and 'completion' columns)")
parser.add_argument('--output', type=str, help='Output file path')
args = parser.parse_args()
df = pd.read_parquet(args.input)
# fit the vectorizer on the prompt column
prompt_tfidf_vectorizer = TfidfVectorizer()
prompt_tfidf_vectorizer.fit(df['prompt'])
# save the vectorizer
joblib.dump(prompt_tfidf_vectorizer, args.output + 'prompt-vectorizer.pkl')
# get the tfidf_matrix
prompt_tfidf_matrix = prompt_tfidf_vectorizer.transform(df['prompt'])
# save the tfidf_matrix
joblib.dump(prompt_tfidf_matrix, args.output + 'prompt-tfidf-matrix.pkl')
# fit the vectorizer on the completion column
completion_tfidf_vectorizer = TfidfVectorizer()
completion_tfidf_vectorizer.fit(df['completion'])
# save the vectorizer
joblib.dump(completion_tfidf_vectorizer, args.output + 'completion-vectorizer.pkl')
# get the tfidf_matrix
completion_tfidf_matrix = completion_tfidf_vectorizer.transform(df['completion'])
# save the tfidf_matrix
joblib.dump(completion_tfidf_matrix, args.output + 'completion-tfidf-matrix.pkl')
print("Done!")
if __name__ == '__main__':
main()
# example usage: python create-tfidf-matrix.py --input fine-tuning-data.parquet --output ./ |