1 line
32 KiB
JSON
1 line
32 KiB
JSON
{"repo": "applied-ai-research-lab/agenticrecommender-agentic-ai-vs-ai-agents-in-recommender-systems-sentiment-analysis-with-llms", "files": {"Classes/DEEPSEEKmethods.py": {"e01e18b0c8dd488ad42018a894826b86d56befc4": {"t": 1785746470.700153, "n": 15903, "h": "e1a51e3398bd6632", "c": "import os\nimport pandas as pd\nimport openai\nfrom openai import OpenAI\nimport json\nimport logging\nimport re\nimport time\nfrom config import DEEPSEEK_API_KEY\n\n\nclass DEEPSEEKmethods:\n def __init__(self, params):\n \"\"\"\n Initialize the class with the provided parameters.\n The constructor sets up the DEEPSEEK API key, model configuration, and various other\n parameters needed for generating prompts and making predictions.\n\n Args:\n params (dict): A dictionary containing the configuration settings.\n \"\"\"\n # Access the DEEPSEEK API key from config file (loaded from .env)\n self.api_key = DEEPSEEK_API_KEY\n\n # Initialize class variables using the provided parameters\n self.model_id = params['model_id'] # The model ID to use (e.g., deepseek-chat)\n self.prediction_column = params['prediction_column'] # Specifies the column where predictions will be stored\n self.pre_path = params['pre_path'] # The path to datasets\n self.data_set = params['data_set'] # Defines the path to the CSV dataset file\n self.prompt_array = params['prompt_array'] # A dictionary with additional data\n self.system = params['system'] # System-level message for context in the conversation\n self.prompt = params['prompt'] # The base prompt template\n self.feature_col = params['feature_col'] # Column name for feature input\n self.label_col = params['label_col'] # Column name for the label\n self.json_key = params['json_key'] # Key for extracting relevant data from the model's response\n self.max_tokens = params['max_tokens'] # Maximum number of tokens to generate in the response\n self.temperature = params['temperature'] # Controls response randomness (0 is most deterministic)\n\n \"\"\"\n Generates a custom prompt\n \"\"\"\n\n def generate_prompt(self, feature):\n\n updated_prompt = self.prompt + feature\n\n # If the prompt is simple you can avoid this method by setting updated_prompt = self.prompt + feature\n return updated_prompt # This method returns the whole new custom prompt\n\n \"\"\"\n Creates a training and validation JSONL file for DeepSeek fine-tuning.\n The method reads a CSV dataset, generates prompt-completion pairs for each row, and formats the data into\n the required JSONL structure for DeepSeek fine-tuning.\n The generated JSONL file will contain system, user, and assistant messages for each training || validation instance.\n \"\"\"\n\n def create_jsonl(self, data_type, data_set):\n # Read the CSV file into a pandas DataFrame\n df = pd.read_csv(self.pre_path + data_set)\n data = [] # List to store the formatted data for each row\n\n # Iterate over each row in the DataFrame to format the data for fine-tuning\n for index, row in df.iterrows():\n data.append(\n {\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": self.system # System message for context\n },\n {\n \"role\": \"user\",\n \"content\": self.generate_prompt(feature=row[self.feature_col]) # Generate user prompt\n },\n {\n \"role\": \"assistant\",\n \"content\": f\"{{{self.json_key}: {row[self.label_col]}}}\" # Assistant's response\n }\n ]\n }\n )\n\n # Define the output file path for the JSONL file\n output_file_path = self.pre_path + \"ft_dataset_deepseek_\" + data_type + \".jsonl\" # Define the path\n # Write the formatted data to the JSONL file\n with open(output_file_path, 'w') as output_file:\n for record in data:\n # Convert each dictionary record to a JSON string and write it to the file\n json_record = json.dumps(record)\n output_file.write(json_record + '\\n')\n\n # Return a success message with the file path\n return {\"status\": True, \"data\": f\"JSONL file '{output_file_path}' has been created.\"}\n\n \"\"\"\n Create a conversation with the DeepSeek model by sending a series of messages and receiving a response.\n This method constructs the conversation and returns the model's reply based on the provided messages.\n \"\"\"\n\n def deepseek_conversation(self, conversation):\n try: # DeepSeek uses OpenAI's SDK\n client = OpenAI(api_key=self.api_key, base_url=\"https://api.deepseek.com\")\n\n completion = client.chat.completions.create(\n model=self.model_id,\n messages=conversation,\n stream=False\n )\n return completion.choices[0].message.content\n except Exception as e:\n print(f\"Error getting response from DeepSeek: {e}\")\n return None\n\n \"\"\"\n Cleans the response from the DeepSeek model by attempting to extract and parse a JSON string.\n If the response is already in dictionary format, it is returned directly.\n If the response contains a JSON string, it will be extracted, cleaned, and parsed.\n If no valid JSON is found or a decoding error occurs, an error message is logged.\n \"\"\"\n\n def clean_response(self, response, a_field):\n if isinstance(response, dict): # If already valid, return it\n return {\"status\": True, \"data\": response}\n\n try:\n if response is None:\n raise ValueError(\"Response is None\")\n\n start_index = response.find('{')\n end_index = response.rfind('}')\n\n if start_index != -1 and end_index != -1:\n json_str = response[start_index:end_index + 1]\n json_str = re.sub(r\"\\'\", '\"', json_str) # Fix single quotes\n json_data = json.loads(json_str) # Parse JSON\n return {\"status\": True, \"data\": json_data}\n else:\n logging.error(f\"No JSON found in response. Input: '{a_field}', Response: {response}\")\n return {\"status\": False, \"data\": f\"No JSON found in response. Input: '{a_field}', Response: {response}\"}\n\n except (json.JSONDecodeError, ValueError) as e:\n logging.error(f\"JSON parsing error: {str(e)}. Input: '{a_field}', Response: {response}\")\n return {\"status\": False, \"data\": f\"JSON parsing error: {str(e)}. Input: '{a_field}', Response: {response}\"}\n\n \"\"\"\n Prompts the DeepSeek model to generate a prediction based on the provided input.\n The method constructs a conversation with the model using the system message and user input, \n and processes the model's response to return a clean, formatted prediction.\n \"\"\"\n\n def deepseek_prediction(self, input):\n conversation = [\n {'role': 'system', 'content': self.system},\n {'role': 'user', 'content': self.generate_prompt(feature=input['title'] + '\\n' + input[self.feature_col])}\n ]\n\n while True:\n conversation_response = self.deepseek_conversation(conversation) # Call the model\n\n if conversation_response is None:\n logging.warning(\"Received None response. Retrying...\")\n time.sleep(1) # Short delay before retrying\n continue\n\n cleaned_response = self.clean_response(response=conversation_response, a_field=input[self.feature_col])\n\n if cleaned_response[\"status\"]: # If response is valid, return it\n return cleaned_response\n\n logging.warning(\"Invalid response format. Retrying...\")\n time.sleep(1) # Short delay before retrying\n\n \"\"\"\n Makes predictions for a specific dataset and append the predictions to a new column.\n This method processes each row in the dataset, generates predictions using the DeepSeek model, \n and updates the dataset with the predicted values in the specified prediction column.\n \"\"\"\n\n def predictions(self):\n\n # Read the CSV dataset into a pandas DataFrame\n df = pd.read_csv(self.pre_path + self.data_set)\n\n # Create a copy of the original dataset (with '_original' appended to the filename)\n file_name_without_extension = os.path.splitext(os.path.basename(self.data_set))[0]\n\n # Rename the original file by appending '_original' to its name\n original_file_path = self.pre_path + file_name_without_extension + '_original.csv'\n if not os.path.exists(original_file_path):\n os.rename(self.pre_path + self.data_set, original_file_path)\n\n # Check if the prediction_column is already present in the header\n if self.prediction_column not in df.columns:\n # If not, add the column to the DataFrame with pd.NA as the initial value\n df[self.prediction_column] = pd.NA\n\n if \"time-\" + self.model_id not in df.columns:\n df[\"time-\" + self.model_id] = pd.NA\n # # Explicitly set the column type to a nullable integer\n # df = df.astype({prediction_column: 'Int64'})\n\n # Save the updated DataFrame back to CSV (if a new column is added)\n if self.prediction_column not in df.columns:\n df.to_csv(self.pre_path + self.data_set, index=False)\n\n # Set the dtype of the reason column to object\n # df = df.astype({reason_column: 'object'})\n\n # Iterate over each row in the DataFrame to make predictions\n for index, row in df.iterrows():\n # Make a prediction if the value in the prediction column is missing (NaN)\n if pd.isnull(row[self.prediction_column]):\n\n start_time = time.time() # Start timer\n\n prediction = self.deepseek_prediction(input=row)\n\n end_time = time.time() # End timer\n elapsed_time = round(end_time - start_time, 4) # Compute elapsed time (rounded to 4 decimal places)\n\n # If the prediction fails, log the error and break the loop\n if not prediction['status']:\n print(prediction)\n break\n else:\n print(prediction)\n # If the prediction data contains a valid value, update the DataFrame\n if prediction['data'][self.json_key] != '':\n # Update the CSV file with the new prediction values\n df.at[index, self.prediction_column] = prediction['data'][self.json_key]\n # for integers only\n # df.at[index, prediction_column] = int(prediction['data'][self.json_key])\n\n df.at[index, \"time-\" + self.model_id] = elapsed_time\n\n # Update the CSV file with the new values\n df.to_csv(self.pre_path + self.data_set, index=False)\n else:\n logging.error(\n f\"No {self.json_key} instance was found within the data for '{row[self.feature_col]}', and the \"\n f\"corresponding prediction response was: {prediction}.\")\n return {\"status\": False,\n \"data\": f\"No {self.json_key} instance was found within the data for '{row[self.feature_col]}', \"\n f\"and the corresponding prediction response was: {prediction}.\"}\n\n # break\n # Add a delay of 5 seconds (reduced for testing)\n\n # Change the column datatype after processing all predictions to handle 2.0 ratings\n # df[prediction_column] = df[prediction_column].astype('Int64')\n\n # After all predictions are made, return a success message\n return {\"status\": True, \"data\": 'Prediction have successfully been'}\n\n\n# TODO: Before running the script:\n# Ensure the DEEPSEEK_API_KEY is set as an environment variable to enable access to the DEEPSEEK API.\n\n\"\"\"\nConfigure the logging module to record error messages in a file named 'error_log.txt'.\n\"\"\"\nlogging.basicConfig(filename='../error_log.txt', level=logging.ERROR)\n\n\"\"\"\nThe `params` dictionary contains configuration settings for the AI model's prediction process. \nIt includes specifications for the model ID, dataset details, system and task-specific prompts, \nand parameters for prediction output, response format, and model behavior.\n\"\"\"\nparams = {\n 'model_id': 'deepseek-chat', # Specifies the DeepSeek model ID for making predictions.\n 'prediction_column': 'deepseek-chat_prediction', # Specifies the column where predictions will be stored.\n 'pre_path': 'Datasets/', # Specifies the base directory path where dataset files are located.\n 'data_set': 'Dataset.csv', # Defines the path to the CSV dataset file.\n 'prompt_array': {}, # Can be an empty array for simple projects.\n # Defines the system prompt that describes the task.\n 'system': 'You are an expert sentiment analysis system for product reviews.',\n # Defines the prompt for the model, instructing it to make predictions and return its response in JSON format.\n # You can pass anything within brackets [example], which will be replaced during generate_prompt().\n 'prompt': '''You are an expert sentiment analysis system for product reviews. Your task is to predict the star rating (1-5) that a user would give based on their review text.\n\nRating scale:\n- 5 stars: Extremely positive, enthusiastic praise\n- 4 stars: Positive with minor reservations\n- 3 stars: Mixed feelings, balanced pros and cons\n- 2 stars: Mostly negative with few positives\n- 1 star: Extremely negative, strong dissatisfaction\n\nAnalyze the review's sentiment, key phrases, and overall tone. Consider:\n- Emotional language (love, hate, disappointed, amazing)\n- Specific praise or complaints\n- Comparison words (better, worse, expected more)\n- Problem severity mentions\n- Recommendation likelihood\n\nOutput only valid JSON with no additional text:\n{\"rating\": <number between 1-5>}\n\nReview:''',\n 'feature_col': 'text', # Specifies the column in the dataset containing the text input/feature for predictions.\n 'label_col': 'rating', # Used only for creating training and validation prompt-completion pairs JSONL files.\n 'json_key': 'rating', # Defines the key in the JSON response expected from the model, e.g. {\"category\": \"value\"}\n 'max_tokens': 1000, # Sets the maximum number of tokens the model should generate in its response.\n 'temperature': 0, # Sets the temperature for response variability; 0 provides the most deterministic response.\n}\n\n# params['model_id'] = 'deepseek-chat' # DeepSeek-V3.2-Exp (Non-thinking Mode)\n# params['prediction_column'] = 'deepseek-chat_prediction'\n\n# params['model_id'] = 'deepseek-reasoner' # DeepSeek-V3.2-Exp (Thinking Mode)\n# params['prediction_column'] = 'deepseek-reasoner_prediction'\n\n# === DeepSeek Model Family ===\n# DeepSeek Chat:\n# • DeepSeek-V3.2-Exp in Non-thinking Mode.\n# • Optimized for straightforward chat and retrieval tasks.\n#\n# DeepSeek Reasoner:\n# • DeepSeek-V3.2-Exp in Thinking Mode.\n# • Designed for reasoning, problem solving, and more complex workflows.\n#\n# --- Pricing (per 1M tokens) ---\n# MODEL | INPUT | CACHED INPUT | OUTPUT\n# -------------------- | ------------- | ------------- | -------\n# DeepSeek Chat | $0.028 | $0.28 | $0.42\n# DeepSeek Reasoner | $0.028 | $0.28 | $0.42\n\n\"\"\"\nCreate an instance of the DEEPSEEKmethods class, passing the `params` dictionary to the constructor for initialization.\n\"\"\"\n# DEEPSEEK = DEEPSEEKmethods(params)\n\n\"\"\"\nCall the `predictions` method of the DEEPSEEKmethods instance to make predictions on the specified dataset.\n\"\"\"\n# DEEPSEEK.predictions()\n"}, "79534fe035964f45e327c99d1fa41f1a7716ae47": {"t": 1785764643.482646, "n": 15903, "h": "e1a51e3398bd6632", "c": "import os\nimport pandas as pd\nimport openai\nfrom openai import OpenAI\nimport json\nimport logging\nimport re\nimport time\nfrom config import DEEPSEEK_API_KEY\n\n\nclass DEEPSEEKmethods:\n def __init__(self, params):\n \"\"\"\n Initialize the class with the provided parameters.\n The constructor sets up the DEEPSEEK API key, model configuration, and various other\n parameters needed for generating prompts and making predictions.\n\n Args:\n params (dict): A dictionary containing the configuration settings.\n \"\"\"\n # Access the DEEPSEEK API key from config file (loaded from .env)\n self.api_key = DEEPSEEK_API_KEY\n\n # Initialize class variables using the provided parameters\n self.model_id = params['model_id'] # The model ID to use (e.g., deepseek-chat)\n self.prediction_column = params['prediction_column'] # Specifies the column where predictions will be stored\n self.pre_path = params['pre_path'] # The path to datasets\n self.data_set = params['data_set'] # Defines the path to the CSV dataset file\n self.prompt_array = params['prompt_array'] # A dictionary with additional data\n self.system = params['system'] # System-level message for context in the conversation\n self.prompt = params['prompt'] # The base prompt template\n self.feature_col = params['feature_col'] # Column name for feature input\n self.label_col = params['label_col'] # Column name for the label\n self.json_key = params['json_key'] # Key for extracting relevant data from the model's response\n self.max_tokens = params['max_tokens'] # Maximum number of tokens to generate in the response\n self.temperature = params['temperature'] # Controls response randomness (0 is most deterministic)\n\n \"\"\"\n Generates a custom prompt\n \"\"\"\n\n def generate_prompt(self, feature):\n\n updated_prompt = self.prompt + feature\n\n # If the prompt is simple you can avoid this method by setting updated_prompt = self.prompt + feature\n return updated_prompt # This method returns the whole new custom prompt\n\n \"\"\"\n Creates a training and validation JSONL file for DeepSeek fine-tuning.\n The method reads a CSV dataset, generates prompt-completion pairs for each row, and formats the data into\n the required JSONL structure for DeepSeek fine-tuning.\n The generated JSONL file will contain system, user, and assistant messages for each training || validation instance.\n \"\"\"\n\n def create_jsonl(self, data_type, data_set):\n # Read the CSV file into a pandas DataFrame\n df = pd.read_csv(self.pre_path + data_set)\n data = [] # List to store the formatted data for each row\n\n # Iterate over each row in the DataFrame to format the data for fine-tuning\n for index, row in df.iterrows():\n data.append(\n {\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": self.system # System message for context\n },\n {\n \"role\": \"user\",\n \"content\": self.generate_prompt(feature=row[self.feature_col]) # Generate user prompt\n },\n {\n \"role\": \"assistant\",\n \"content\": f\"{{{self.json_key}: {row[self.label_col]}}}\" # Assistant's response\n }\n ]\n }\n )\n\n # Define the output file path for the JSONL file\n output_file_path = self.pre_path + \"ft_dataset_deepseek_\" + data_type + \".jsonl\" # Define the path\n # Write the formatted data to the JSONL file\n with open(output_file_path, 'w') as output_file:\n for record in data:\n # Convert each dictionary record to a JSON string and write it to the file\n json_record = json.dumps(record)\n output_file.write(json_record + '\\n')\n\n # Return a success message with the file path\n return {\"status\": True, \"data\": f\"JSONL file '{output_file_path}' has been created.\"}\n\n \"\"\"\n Create a conversation with the DeepSeek model by sending a series of messages and receiving a response.\n This method constructs the conversation and returns the model's reply based on the provided messages.\n \"\"\"\n\n def deepseek_conversation(self, conversation):\n try: # DeepSeek uses OpenAI's SDK\n client = OpenAI(api_key=self.api_key, base_url=\"https://api.deepseek.com\")\n\n completion = client.chat.completions.create(\n model=self.model_id,\n messages=conversation,\n stream=False\n )\n return completion.choices[0].message.content\n except Exception as e:\n print(f\"Error getting response from DeepSeek: {e}\")\n return None\n\n \"\"\"\n Cleans the response from the DeepSeek model by attempting to extract and parse a JSON string.\n If the response is already in dictionary format, it is returned directly.\n If the response contains a JSON string, it will be extracted, cleaned, and parsed.\n If no valid JSON is found or a decoding error occurs, an error message is logged.\n \"\"\"\n\n def clean_response(self, response, a_field):\n if isinstance(response, dict): # If already valid, return it\n return {\"status\": True, \"data\": response}\n\n try:\n if response is None:\n raise ValueError(\"Response is None\")\n\n start_index = response.find('{')\n end_index = response.rfind('}')\n\n if start_index != -1 and end_index != -1:\n json_str = response[start_index:end_index + 1]\n json_str = re.sub(r\"\\'\", '\"', json_str) # Fix single quotes\n json_data = json.loads(json_str) # Parse JSON\n return {\"status\": True, \"data\": json_data}\n else:\n logging.error(f\"No JSON found in response. Input: '{a_field}', Response: {response}\")\n return {\"status\": False, \"data\": f\"No JSON found in response. Input: '{a_field}', Response: {response}\"}\n\n except (json.JSONDecodeError, ValueError) as e:\n logging.error(f\"JSON parsing error: {str(e)}. Input: '{a_field}', Response: {response}\")\n return {\"status\": False, \"data\": f\"JSON parsing error: {str(e)}. Input: '{a_field}', Response: {response}\"}\n\n \"\"\"\n Prompts the DeepSeek model to generate a prediction based on the provided input.\n The method constructs a conversation with the model using the system message and user input, \n and processes the model's response to return a clean, formatted prediction.\n \"\"\"\n\n def deepseek_prediction(self, input):\n conversation = [\n {'role': 'system', 'content': self.system},\n {'role': 'user', 'content': self.generate_prompt(feature=input['title'] + '\\n' + input[self.feature_col])}\n ]\n\n while True:\n conversation_response = self.deepseek_conversation(conversation) # Call the model\n\n if conversation_response is None:\n logging.warning(\"Received None response. Retrying...\")\n time.sleep(1) # Short delay before retrying\n continue\n\n cleaned_response = self.clean_response(response=conversation_response, a_field=input[self.feature_col])\n\n if cleaned_response[\"status\"]: # If response is valid, return it\n return cleaned_response\n\n logging.warning(\"Invalid response format. Retrying...\")\n time.sleep(1) # Short delay before retrying\n\n \"\"\"\n Makes predictions for a specific dataset and append the predictions to a new column.\n This method processes each row in the dataset, generates predictions using the DeepSeek model, \n and updates the dataset with the predicted values in the specified prediction column.\n \"\"\"\n\n def predictions(self):\n\n # Read the CSV dataset into a pandas DataFrame\n df = pd.read_csv(self.pre_path + self.data_set)\n\n # Create a copy of the original dataset (with '_original' appended to the filename)\n file_name_without_extension = os.path.splitext(os.path.basename(self.data_set))[0]\n\n # Rename the original file by appending '_original' to its name\n original_file_path = self.pre_path + file_name_without_extension + '_original.csv'\n if not os.path.exists(original_file_path):\n os.rename(self.pre_path + self.data_set, original_file_path)\n\n # Check if the prediction_column is already present in the header\n if self.prediction_column not in df.columns:\n # If not, add the column to the DataFrame with pd.NA as the initial value\n df[self.prediction_column] = pd.NA\n\n if \"time-\" + self.model_id not in df.columns:\n df[\"time-\" + self.model_id] = pd.NA\n # # Explicitly set the column type to a nullable integer\n # df = df.astype({prediction_column: 'Int64'})\n\n # Save the updated DataFrame back to CSV (if a new column is added)\n if self.prediction_column not in df.columns:\n df.to_csv(self.pre_path + self.data_set, index=False)\n\n # Set the dtype of the reason column to object\n # df = df.astype({reason_column: 'object'})\n\n # Iterate over each row in the DataFrame to make predictions\n for index, row in df.iterrows():\n # Make a prediction if the value in the prediction column is missing (NaN)\n if pd.isnull(row[self.prediction_column]):\n\n start_time = time.time() # Start timer\n\n prediction = self.deepseek_prediction(input=row)\n\n end_time = time.time() # End timer\n elapsed_time = round(end_time - start_time, 4) # Compute elapsed time (rounded to 4 decimal places)\n\n # If the prediction fails, log the error and break the loop\n if not prediction['status']:\n print(prediction)\n break\n else:\n print(prediction)\n # If the prediction data contains a valid value, update the DataFrame\n if prediction['data'][self.json_key] != '':\n # Update the CSV file with the new prediction values\n df.at[index, self.prediction_column] = prediction['data'][self.json_key]\n # for integers only\n # df.at[index, prediction_column] = int(prediction['data'][self.json_key])\n\n df.at[index, \"time-\" + self.model_id] = elapsed_time\n\n # Update the CSV file with the new values\n df.to_csv(self.pre_path + self.data_set, index=False)\n else:\n logging.error(\n f\"No {self.json_key} instance was found within the data for '{row[self.feature_col]}', and the \"\n f\"corresponding prediction response was: {prediction}.\")\n return {\"status\": False,\n \"data\": f\"No {self.json_key} instance was found within the data for '{row[self.feature_col]}', \"\n f\"and the corresponding prediction response was: {prediction}.\"}\n\n # break\n # Add a delay of 5 seconds (reduced for testing)\n\n # Change the column datatype after processing all predictions to handle 2.0 ratings\n # df[prediction_column] = df[prediction_column].astype('Int64')\n\n # After all predictions are made, return a success message\n return {\"status\": True, \"data\": 'Prediction have successfully been'}\n\n\n# TODO: Before running the script:\n# Ensure the DEEPSEEK_API_KEY is set as an environment variable to enable access to the DEEPSEEK API.\n\n\"\"\"\nConfigure the logging module to record error messages in a file named 'error_log.txt'.\n\"\"\"\nlogging.basicConfig(filename='../error_log.txt', level=logging.ERROR)\n\n\"\"\"\nThe `params` dictionary contains configuration settings for the AI model's prediction process. \nIt includes specifications for the model ID, dataset details, system and task-specific prompts, \nand parameters for prediction output, response format, and model behavior.\n\"\"\"\nparams = {\n 'model_id': 'deepseek-chat', # Specifies the DeepSeek model ID for making predictions.\n 'prediction_column': 'deepseek-chat_prediction', # Specifies the column where predictions will be stored.\n 'pre_path': 'Datasets/', # Specifies the base directory path where dataset files are located.\n 'data_set': 'Dataset.csv', # Defines the path to the CSV dataset file.\n 'prompt_array': {}, # Can be an empty array for simple projects.\n # Defines the system prompt that describes the task.\n 'system': 'You are an expert sentiment analysis system for product reviews.',\n # Defines the prompt for the model, instructing it to make predictions and return its response in JSON format.\n # You can pass anything within brackets [example], which will be replaced during generate_prompt().\n 'prompt': '''You are an expert sentiment analysis system for product reviews. Your task is to predict the star rating (1-5) that a user would give based on their review text.\n\nRating scale:\n- 5 stars: Extremely positive, enthusiastic praise\n- 4 stars: Positive with minor reservations\n- 3 stars: Mixed feelings, balanced pros and cons\n- 2 stars: Mostly negative with few positives\n- 1 star: Extremely negative, strong dissatisfaction\n\nAnalyze the review's sentiment, key phrases, and overall tone. Consider:\n- Emotional language (love, hate, disappointed, amazing)\n- Specific praise or complaints\n- Comparison words (better, worse, expected more)\n- Problem severity mentions\n- Recommendation likelihood\n\nOutput only valid JSON with no additional text:\n{\"rating\": <number between 1-5>}\n\nReview:''',\n 'feature_col': 'text', # Specifies the column in the dataset containing the text input/feature for predictions.\n 'label_col': 'rating', # Used only for creating training and validation prompt-completion pairs JSONL files.\n 'json_key': 'rating', # Defines the key in the JSON response expected from the model, e.g. {\"category\": \"value\"}\n 'max_tokens': 1000, # Sets the maximum number of tokens the model should generate in its response.\n 'temperature': 0, # Sets the temperature for response variability; 0 provides the most deterministic response.\n}\n\n# params['model_id'] = 'deepseek-chat' # DeepSeek-V3.2-Exp (Non-thinking Mode)\n# params['prediction_column'] = 'deepseek-chat_prediction'\n\n# params['model_id'] = 'deepseek-reasoner' # DeepSeek-V3.2-Exp (Thinking Mode)\n# params['prediction_column'] = 'deepseek-reasoner_prediction'\n\n# === DeepSeek Model Family ===\n# DeepSeek Chat:\n# • DeepSeek-V3.2-Exp in Non-thinking Mode.\n# • Optimized for straightforward chat and retrieval tasks.\n#\n# DeepSeek Reasoner:\n# • DeepSeek-V3.2-Exp in Thinking Mode.\n# • Designed for reasoning, problem solving, and more complex workflows.\n#\n# --- Pricing (per 1M tokens) ---\n# MODEL | INPUT | CACHED INPUT | OUTPUT\n# -------------------- | ------------- | ------------- | -------\n# DeepSeek Chat | $0.028 | $0.28 | $0.42\n# DeepSeek Reasoner | $0.028 | $0.28 | $0.42\n\n\"\"\"\nCreate an instance of the DEEPSEEKmethods class, passing the `params` dictionary to the constructor for initialization.\n\"\"\"\n# DEEPSEEK = DEEPSEEKmethods(params)\n\n\"\"\"\nCall the `predictions` method of the DEEPSEEKmethods instance to make predictions on the specified dataset.\n\"\"\"\n# DEEPSEEK.predictions()\n"}}}} |