def register(class_):
    """Registers a new word embedding evaluation function.

    Once registered, we can create an instance with
    :func:`~gluonnlp.embedding.evaluation.create`.

    Examples
    --------
    >>> @gluonnlp.embedding.evaluation.register
    ... class MySimilarityFunction(gluonnlp.embedding.evaluation.WordEmbeddingSimilarityFunction):
    ...     def __init__(self, eps=1e-10):
    ...         pass
    >>> similarity_function = gluonnlp.embedding.evaluation.create('similarity',
    ...                                                            'MySimilarityFunction')
    >>> print(type(similarity_function))
    <class 'MySimilarityFunction'>

    >>> @gluonnlp.embedding.evaluation.register
    ... class MyAnalogyFunction(gluonnlp.embedding.evaluation.WordEmbeddingAnalogyFunction):
    ...     def __init__(self, k=1, eps=1E-10):
    ...         pass
    >>> analogy_function = gluonnlp.embedding.evaluation.create('analogy', 'MyAnalogyFunction')
    >>> print(type(analogy_function))
    <class 'MyAnalogyFunction'>

    """

    if issubclass(class_, WordEmbeddingSimilarityFunction):
        register_ = registry.get_register_func(
            WordEmbeddingSimilarityFunction,
            'word embedding similarity evaluation function')
    elif issubclass(class_, WordEmbeddingAnalogyFunction):
        register_ = registry.get_register_func(
            WordEmbeddingAnalogyFunction,
            'word embedding analogy evaluation function')
    else:
        raise RuntimeError(
            'The custom function must either subclass '
            'WordEmbeddingSimilarityFunction or WordEmbeddingAnalogyFunction')

    return register_(class_)
def register ( class_ ) : if issubclass ( class_ , WordEmbeddingSimilarityFunction ) : register_ = registry . get_register_func ( WordEmbeddingSimilarityFunction , 'word embedding similarity evaluation function' ) elif issubclass ( class_ , WordEmbeddingAnalogyFunction ) : register_ = registry . get_register_func ( WordEmbeddingAnalogyFunction , 'word embedding analogy evaluation function' ) else : raise RuntimeError ( 'The custom function must either subclass ' 'WordEmbeddingSimilarityFunction or WordEmbeddingAnalogyFunction' ) return register_ ( class_ )
Registers a new word embedding evaluation function.

    Once registered, we can create an instance with
    :func:`~gluonnlp.embedding.evaluation.create`.

    Examples
    --------
    >>> @gluonnlp.embedding.evaluation.register
    ... class MySimilarityFunction(gluonnlp.embedding.evaluation.WordEmbeddingSimilarityFunction):
    ...     def __init__(self, eps=1e-10):
    ...         pass
    >>> similarity_function = gluonnlp.embedding.evaluation.create('similarity',
    ...                                                            'MySimilarityFunction')
    >>> print(type(similarity_function))
    <class 'MySimilarityFunction'>

    >>> @gluonnlp.embedding.evaluation.register
    ... class MyAnalogyFunction(gluonnlp.embedding.evaluation.WordEmbeddingAnalogyFunction):
    ...     def __init__(self, k=1, eps=1E-10):
    ...         pass
    >>> analogy_function = gluonnlp.embedding.evaluation.create('analogy', 'MyAnalogyFunction')
    >>> print(type(analogy_function))
    <class 'MyAnalogyFunction'>