In this script, how can I load the saved pickle? import os import pandas as pd import…
- User
In this script, how can I load the saved pickle?
import os import pandas as pd
import config
from datasets import TopicalDocuments from soft_topics_generator import TitleSetGenerator
num_output_topics = 6
model_name = 'gpt-4o'
model_name = 'gpt-4-0125-preview'
model_name = 'gpt-4.1-2025-04-14' temperature = 0 num_iterations = 6
print(f'Generating title sets for model: {model_name}')
workdir = 'title_sets/domestic_resilience' output_fname = workdir + os.sep + f'{model_name}title_sets{num_output_topics}temp{temperature}_{num_iterations}_iterations.pkl'
documents = pd.read_pickle('preprocess/df_for_clustering.pkl')
generator = TitleSetGenerator( model_name=model_name, num_topics=num_output_topics, num_iterations=num_iterations, # num_iterations=40, dynamic_intermediate_num_topics=True, final_num_topics_aggregation='num_topics', temperature=temperature )
title_sets = []
Generate soft topics over the entire corpus
print('########## Generating soft topics for the entire dataset ##########')
documents = data['content'].tolist()
title_set, intermediate_titles = generator.generate_title_set(documents)
for i, title in enumerate(title_set): title_sets.append([model_name, 'ALL_DOCUMENTS', i, title, intermediate_titles])
title_sets = pd.DataFrame(title_sets, columns=['generation_method', 'story_group', 'title_rank', 'generated_title', 'info'])
save the title sets to a pickle file
title_sets.to_pickle(output_fname)
- Assistant
Use pd.read_pickle: pythonCopyEditimport pandas as pd from pathlib import Path
workdir = Path('title_sets/domestic_resilience') model_name = 'gpt-4.1-2025-04-14' num_output_topics = 6 temperature = 0 num_iterations = 6
output_fname = workdir / f'{model_name}title_sets{num_output_topics}temp{temperature}_{num_iterations}_iterations.pkl'
title_sets = pd.read_pickle(output_fname) print(title_sets.head())
If you don’t still have the variables around and just want to load “the only .pkl in that dir”, you could: pythonCopyEditimport pandas as pd from pathlib import Path
workdir = Path('title_sets/domestic_resilience') output_fname = next(workdir.glob('*.pkl')) title_sets = pd.read_pickle(output_fname)
(Reminder: pickle is not secure—only load files you trust.)