API
Recomendation
recomend.py
chat(text)
A function that takes in a text message as a parameter and returns AI-generated text responses using GPT4All model.
Parameters
str
A string representing the input text message.
Returns
list A list of AI-generated text responses.
Example
chat("Hello, how are you?") ["I'm fine, thank you. How about yourself?"]
Source code in src/recomend.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
chat_t5(text, **kwargs)
Initializes the chatbot model and returns the model name.
Parameters
str
The input text to be processed by the chatbot model.
**kwargs : dict Optional keyword arguments to be passed to the chatbot model.
Returns
str The name of the chatbot model.
Source code in src/recomend.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
popular_items(data, data_items, genre=None, threshold_progress=40, n_items=10)
Recomends the top n popular items for a given genre.
Parameters
pd.DataFrame
dataframe containing the user-item interactions
pd.DataFrame
dataframe containing the items
str
genre of the items to be recommended
int, optional
threshold of progress items, by default 40
int, optional
count items to be return, by default 10
Returns
np.ndarray
the top n popular items for a given genre
Source code in src/recomend.py
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
recomend_als(user_id)
Recommends books using the ALS algorithm.
Parameters
int
The ID of the user to find similar books to.
Returns
pandas.DataFrame A DataFrame containing information about the similar books.
Source code in src/recomend.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
recomend_bm25(item_id)
Recommends books similar to a given book ID using the BM25 algorithm.
Parameters
int
The ID of the book to find similar books to.
Returns
pandas.DataFrame A DataFrame containing information about the similar books.
Source code in src/recomend.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
summarize(input_sequences)
Summarizes the input text
Parameters
str
The input text to be summarized
Returns
str summarized text
Source code in src/recomend.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
Utils
Utils.
create_weighted_interaction_matrix(data, alpha=0.01)
Create a weighted interaction matrix based on the input DataFrame.
Parameters
pd.DataFrame
The input DataFrame containing interactions between users and items.
float, optional
A hyperparameter used to weight interactions based on recency. Default is 0.01.
Returns
Tuple[pd.DataFrame, sp.coo_matrix] The input DataFrame with added columns for days since interaction, weight, and target, and a sparse matrix representing the weighted interactions.
Source code in src/utils.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
read_data(path)
Reads data from csv files located at given path.
Parameters
str
The path where the csv files are located.
Returns
tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame] A tuple containing three pandas DataFrames representing the data, users, and items csv files, respectively.
Raises
AssertionError If any of the csv files are not found at the given path.
Source code in src/utils.py
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 47 48 49 | |
Validation
fit_implicit_als(train_sparse, test_sparse=None, iterations=15, factors=20, regularization=0.1, alpha=40, fold=0)
Fits an implicit ALS model using the given training sparse matrix. Optionally evaluates the model using the given test sparse matrix and logs the results to Weights & Biases. If no test sparse matrix is given, the trained model is pickled and saved to disk.
Parameters
scipy.sparse.csr_matrix
The training sparse matrix.
scipy.sparse.csr_matrix, optional
The test sparse matrix.
int, optional
The number of iterations to run the ALS algorithm. Default is 15.
int, optional
The number of latent factors to use in the model. Default is 20.
float, optional
The regularization parameter to use in the ALS algorithm. Default is 0.1.
int, optional
The alpha hyperparameter to use in the confidence matrix of the ALS algorithm. Default is 40.
bool, optional
Whether to log the results to Weights & Biases. Default is True.
Returns
None
Source code in src/validation.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
fit_implicit_bm25(train_sparse, test_sparse=None, fold=0)
Fits an implicit ALS model using the given training sparse matrix. Optionally evaluates the model using the given test sparse matrix and logs the results to Weights & Biases. If no test sparse matrix is given, the trained model is pickled and saved to disk.
Parameters
scipy.sparse.csr_matrix
The training sparse matrix.
scipy.sparse.csr_matrix, optional
The test sparse matrix.
bool, optional
Whether to log the results to Weights & Biases. Default is True.
Returns
None
Source code in src/validation.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
split_train_test_users(interactions, num_folds=5)
Splits the interactions dataframe into train and test sets by unique users using k-fold cross-validation.
Parameters
pandas.DataFrame
The interactions dataframe.
int, optional
The number of folds for k-fold cross-validation. Default is 5.
Yields
tuple A tuple of pandas.DataFrames containing the train and test sets, respectively.
Source code in src/validation.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
App
create_product_card(st, k, data)
Creates k columns with data in Streamlit.
Parameters
streamlit
The Streamlit library.
int
The number of columns to create.
list
The list of dictionaries containing the data.
Source code in app.py
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 47 48 49 50 51 52 | |