# Copyright 2019-2020 The ASReview Authors. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
from sentence_transformers.SentenceTransformer import SentenceTransformer # noqa
ST_AVAILABLE = False
ST_AVAILABLE = True
from asreview.models.feature_extraction.base import BaseFeatureExtraction
if not ST_AVAILABLE:
"Install sentence_transformers package (`pip install "
"sentence_transformers`) to use 'SBERT' model.")
"""Sentence BERT class for feature extraction.
Feature extraction method based on Sentence BERT. Implementation based on
the `sentence_transformers <https://github.com/UKPLab/sentence-
transformers>`__ package. It is relatively slow.
This feature extraction algorithm requires ``sentence_transformers``
to be installed. Use ``pip install sentence_transformers`` or install
all optional ASReview dependencies with ``pip install asreview[all]``
name = "sbert"
[docs] def transform(self, texts):
model = SentenceTransformer('bert-base-nli-mean-tokens')
X = np.array(model.encode(texts))