import copy import json import tensorflow as tf import numpy as np from overrides import overrides from deeppavlov.core.models.nn_model import NNModel from deeppavlov.core.common.registry import register from deeppavlov.core.common.log import get_logger from deeppavlov.core.commands.utils import expand_path from deeppavlov.models.elmo.bilm_model import LanguageModel from deeppavlov.models.elmo.train_utils import average_gradients, clip_grads, safely_str2int, dump_weights from deeppavlov.models.elmo.elmo2tfhub import export2hub log = get_logger(__name__) @register('elmo_model') class ELMo(NNModel): """ The :class:`~deeppavlov.models.elmo.elmo.ELMo` is a deep contextualized word representation that models both complex characteristics of word use (e.g., syntax and semantics), and how these uses vary across linguistic contexts (i.e., to model polysemy). You can use this component for LM training, fine tuning, dumping ELMo to a hdf5 file and wrapping it to the tensorflow hub. Parameters: options_json_path: Path to the json configure.
# limitations under the License. from typing import List, Tuple, Union import numpy as np from scipy.sparse import vstack, csr_matrix from scipy.sparse.linalg import norm as sparse_norm from deeppavlov.core.common.registry import register from deeppavlov.core.common.log import get_logger from deeppavlov.core.models.estimator import Estimator from deeppavlov.core.common.file import save_pickle from deeppavlov.core.common.file import load_pickle from deeppavlov.core.models.serializable import Serializable logger = get_logger(__name__) @register("cos_sim_classifier") class CosineSimilarityClassifier(Estimator, Serializable): """ Classifier based on cosine similarity between vectorized sentences Parameters: save_path: path to save the model load_path: path to load the model """ def __init__(self, top_n: int = 1, save_path: str = None, load_path: str = None,