:py:mod:`medcat.linking.vector_context_model` ============================================= .. py:module:: medcat.linking.vector_context_model Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: medcat.linking.vector_context_model.ContextModel Attributes ~~~~~~~~~~ .. autoapisummary:: medcat.linking.vector_context_model.logger .. py:data:: logger .. py:class:: ContextModel(cdb, vocab, config) Bases: :py:obj:`object` Used to learn embeddings for concepts and calculate similarities in new documents. :param cdb: The Context Database :type cdb: CDB :param vocab: The vocabulary :type vocab: Vocab :param config: The config to be used :type config: Config .. py:method:: __init__(cdb, vocab, config) .. py:method:: get_context_tokens(entity, doc, size) Get context tokens for an entity, this will skip anything that is marked as skip in token._.to_skip :param entity: The entity to look for. :type entity: Span :param doc: The document look in. :type doc: Doc :param size: The size of the entity. :type size: int :Returns: **Tuple** -- The tokens on the left, centre, and right. .. py:method:: get_context_vectors(entity, doc, cui=None) Given an entity and the document it will return the context representation for the given entity. :param entity: The entity to look for. :type entity: Span :param doc: The document to look in. :type doc: Doc :param cui: The CUI. :type cui: Any :Returns: **Dict** -- The context vector. .. py:method:: similarity(cui, entity, doc) Calculate the similarity between the learnt context for this CUI and the context in the given `doc`. :param cui: The CUI. :type cui: str :param entity: The entity to look for. :type entity: Span :param doc: The document to look in. :type doc: Doc :Returns: **float** -- The similarity. .. py:method:: _similarity(cui, vectors) Calculate similarity once we have vectors and a cui. :param cui: The CUI. :type cui: str :param vectors: The vectors. :type vectors: Dict :Returns: **float** -- The similarity. .. py:method:: disambiguate(cuis, entity, name, doc) .. py:method:: train(cui, entity, doc, negative = False, names = []) Update the context representation for this CUI, given it's correct location (entity) in a document (doc). :param cui: The CUI to train. :type cui: str :param entity: The entity we're at. :type entity: Span :param doc: The document within which we're working. :type doc: Doc :param negative: Whether or not the example is negative. Defaults to False. :type negative: bool :param names: Optionally used to update the `status` of a name-cui pair in the CDB. :type names: List[str]/Dict .. py:method:: train_using_negative_sampling(cui)