def get_similar(self, example, max_similars=<NUM_LIT:3>, similarity_cutoff=None,<EOL>term_diff_max_rank=<NUM_LIT:10>, filter_list=None,<EOL>term_diff_cutoff=None):
if term_diff_cutoff:<EOL><INDENT>warnings.warn('<STR_LIT>',<EOL>DeprecationWarning)<EOL><DEDENT>if filter_list:<EOL><INDENT>if max_similars > len(filter_list):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>filt_idx = np.in1d(self.ids, filter_list)<EOL><DEDENT><DEDENT>elif max_similars > self.term_mat.shape[<NUM_LIT:0>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>filt_idx = np.ones(len(self.ids), dtype=bool)<EOL><DEDENT>good_ids = np.array(np.sum(self.term_mat, <NUM_LIT:1>) > <NUM_LIT:0>).squeeze()<EOL>filt_idx = filt_idx & good_ids<EOL>filt_idx_to_general_idx = np.flatnonzero(filt_idx)<EOL>if example in self.ids:<EOL><INDENT>index = self.ids == example<EOL>exmpl_vec = self.tfidf_mat[index, :]<EOL>distances = np.squeeze(pairwise_distances(self.tfidf_mat[filt_idx],<EOL>exmpl_vec))<EOL>if filter_list and example in filter_list:<EOL><INDENT>distances[filter_list.index(example)] = np.inf<EOL><DEDENT>elif not filter_list:<EOL><INDENT>idx_example = np.searchsorted(self.ids, example)<EOL>filt_idx_example = np.searchsorted(np.flatnonzero(filt_idx),<EOL>idx_example)<EOL>distances[filt_idx_example] = np.inf<EOL><DEDENT><DEDENT>else:<EOL><INDENT>exmpl_vec = self.vectorizer.transform([example])  <EOL>exmpl_vec = self.transformer.transform(exmpl_vec)  <EOL>distances = np.squeeze(pairwise_distances(self.tfidf_mat[filt_idx],<EOL>exmpl_vec))<EOL><DEDENT>if np.sum(exmpl_vec) == <NUM_LIT:0>:<EOL><INDENT>return [], [], []<EOL><DEDENT>sorted_indices = np.argsort(distances)<EOL>closest_n = sorted_indices[:max_similars]<EOL>sorted_dist = distances[closest_n]<EOL>if similarity_cutoff:<EOL><INDENT>closest_n = closest_n[sorted_dist < similarity_cutoff]<EOL>sorted_dist = sorted_dist[sorted_dist < similarity_cutoff]<EOL><DEDENT>best_words = []<EOL>best_example = np.squeeze(exmpl_vec.toarray())<EOL>sorted_example_weights = np.flipud(np.argsort(best_example))<EOL>truncated_max_rank = min(term_diff_max_rank, np.sum(best_example > <NUM_LIT:0>))<EOL>best_example_words = sorted_example_weights[:truncated_max_rank]<EOL>for suggested in closest_n:<EOL><INDENT>suggested_idx = filt_idx_to_general_idx[suggested]<EOL>test_vec = np.squeeze(self.tfidf_mat[suggested_idx, :].toarray())<EOL>sorted_test_weights = np.flipud(np.argsort(test_vec))<EOL>truncated_max_rank = min(term_diff_max_rank,<EOL>np.sum(test_vec > <NUM_LIT:0>))<EOL>best_test = sorted_test_weights[:truncated_max_rank]<EOL>best_words_ids = np.intersect1d(best_example_words, best_test)<EOL>best_words.append([k for k, v in<EOL>self.vectorizer.vocabulary_.items()<EOL>if v in best_words_ids])<EOL><DEDENT>if filter_list:<EOL><INDENT>text_ids = self.ids[filt_idx_to_general_idx[closest_n]]<EOL><DEDENT>else:<EOL><INDENT>text_ids = self.ids[closest_n]<EOL><DEDENT>return list(text_ids), list(sorted_dist), best_words<EOL>
Devuelve textos similares al ejemplo dentro de los textos entrenados.

        Nota:
            Usa la distancia de coseno del vector de features TF-IDF

        Args:
            example (str): Se espera un id de texto o un texto a partir del
                cual se buscaran otros textos similares.
            max_similars (int, optional): Cantidad de textos similares a
                devolver.
            similarity_cutoff (float, optional): Valor umbral de similaridad
                para definir que dos textos son similares entre si.
            term_diff_max_rank (int, optional): Este valor sirve para controlar
                el umbral con el que los terminos son considerados importantes
                a la hora de recuperar textos (no afecta el funcionamiento de
                que textos se consideran cercanos, solo la cantidad de terminos
                que se devuelven en best_words).
            filter_list (list): Lista de ids de textos en la cual buscar textos
                similares.
            term_diff_cutoff (float): Deprecado. Se quitara en el futuro.

        Returns:
            tuple (list, list, list): (text_ids, sorted_dist, best_words)
                text_ids (list of str): Devuelve los ids de los textos
                    sugeridos.
                sorted_dist (list of float): Devuelve la distancia entre las
                    opciones sugeridas y el ejemplo dado como entrada.
                best_words (list of list): Para cada sugerencia devuelve las
                    palabras mas relevantes que se usaron para seleccionar esa
                    sugerencia.