From d9bc00559d42f1caeab1c07eac073688d9d48e82 Mon Sep 17 00:00:00 2001 From: micost Date: Tue, 21 May 2024 14:50:00 +0000 Subject: [PATCH 1/6] feat add cross encoder Signed-off-by: micost --- src/kimchima/pkg/cross_encoder_factory.py | 302 ++++++++++++++++++++++ 1 file changed, 302 insertions(+) create mode 100644 src/kimchima/pkg/cross_encoder_factory.py diff --git a/src/kimchima/pkg/cross_encoder_factory.py b/src/kimchima/pkg/cross_encoder_factory.py new file mode 100644 index 0000000..9ccae5a --- /dev/null +++ b/src/kimchima/pkg/cross_encoder_factory.py @@ -0,0 +1,302 @@ +from functools import wraps + +from transformers import AutoModelForSequenceClassification, AutoTokenizer, AutoConfig +import numpy as np +import logging +import os +from typing import Dict, Type, Callable, List, Optional +import torch +from torch import nn +from torch.optim import Optimizer +from torch.utils.data import DataLoader +from tqdm.autonotebook import tqdm, trange +from transformers import is_torch_npu_available +from transformers.utils import PushToHubMixin + +from .. import SentenceTransformer, util +from ..evaluation import SentenceEvaluator +from ..util import get_device_name + + +logger = logging.getLogger(__name__) + + +class CrossEncoderFactory(PushToHubMixin): + """ + A CrossEncoder takes exactly two sentences / texts as input and either predicts + a score or label for this sentence pair. It can for example predict the similarity of the sentence pair + on a scale of 0 ... 1. + + It does not yield a sentence embedding and does not work for individual sentences. + + :param model_name: A model name from Hugging Face Hub that can be loaded with AutoModel, or a path to a local + model. We provide several pre-trained CrossEncoder models that can be used for common tasks. + :param num_labels: Number of labels of the classifier. If 1, the CrossEncoder is a regression model that + outputs a continuous score 0...1. If > 1, it output several scores that can be soft-maxed to get + probability scores for the different classes. + :param max_length: Max length for input sequences. Longer sequences will be truncated. If None, max + length of the model will be used + :param device: Device that should be used for the model. If None, it will use CUDA if available. + :param tokenizer_args: Arguments passed to AutoTokenizer + :param automodel_args: Arguments passed to AutoModelForSequenceClassification + :param trust_remote_code: Whether or not to allow for custom models defined on the Hub in their own modeling files. + This option should only be set to True for repositories you trust and in which you have read the code, as it + will execute code present on the Hub on your local machine. + :param revision: The specific model version to use. It can be a branch name, a tag name, or a commit id, + for a stored model on Hugging Face. + :param local_files_only: If `True`, avoid downloading the model. + :param default_activation_function: Callable (like nn.Sigmoid) about the default activation function that + should be used on-top of model.predict(). If None. nn.Sigmoid() will be used if num_labels=1, + else nn.Identity() + :param classifier_dropout: The dropout ratio for the classification head. + """ + + def __init__( + self, + model_name: str, + num_labels: int = None, + max_length: int = None, + device: str = None, + tokenizer_args: Dict = {}, + automodel_args: Dict = {}, + trust_remote_code: bool = False, + revision: Optional[str] = None, + local_files_only: bool = False, + default_activation_function=None, + classifier_dropout: float = None, + ): + self.config = AutoConfig.from_pretrained( + model_name, trust_remote_code=trust_remote_code, revision=revision, local_files_only=local_files_only + ) + classifier_trained = True + if self.config.architectures is not None: + classifier_trained = any( + [arch.endswith("ForSequenceClassification") for arch in self.config.architectures] + ) + + if classifier_dropout is not None: + self.config.classifier_dropout = classifier_dropout + + if num_labels is None and not classifier_trained: + num_labels = 1 + + if num_labels is not None: + self.config.num_labels = num_labels + self.model = AutoModelForSequenceClassification.from_pretrained( + model_name, + config=self.config, + revision=revision, + trust_remote_code=trust_remote_code, + local_files_only=local_files_only, + **automodel_args, + ) + self.tokenizer = AutoTokenizer.from_pretrained( + model_name, + revision=revision, + local_files_only=local_files_only, + trust_remote_code=trust_remote_code, + **tokenizer_args, + ) + self.max_length = max_length + + if device is None: + device = get_device_name() + logger.info("Use pytorch device: {}".format(device)) + + self._target_device = torch.device(device) + + if default_activation_function is not None: + self.default_activation_function = default_activation_function + try: + self.config.sbert_ce_default_activation_function = util.fullname(self.default_activation_function) + except Exception as e: + logger.warning( + "Was not able to update config about the default_activation_function: {}".format(str(e)) + ) + elif ( + hasattr(self.config, "sbert_ce_default_activation_function") + and self.config.sbert_ce_default_activation_function is not None + ): + self.default_activation_function = util.import_from_string( + self.config.sbert_ce_default_activation_function + )() + else: + self.default_activation_function = nn.Sigmoid() if self.config.num_labels == 1 else nn.Identity() + + def smart_batching_collate_text_only(self, batch): + texts = [[] for _ in range(len(batch[0]))] + + for example in batch: + for idx, text in enumerate(example): + texts[idx].append(text.strip()) + + tokenized = self.tokenizer( + *texts, padding=True, truncation="longest_first", return_tensors="pt", max_length=self.max_length + ) + + for name in tokenized: + tokenized[name] = tokenized[name].to(self._target_device) + + return tokenized + + def predict( + self, + sentences: List[List[str]], + batch_size: int = 32, + show_progress_bar: bool = None, + num_workers: int = 0, + activation_fct=None, + apply_softmax=False, + convert_to_numpy: bool = True, + convert_to_tensor: bool = False, + ): + """ + Performs predicts with the CrossEncoder on the given sentence pairs. + + :param sentences: A list of sentence pairs [[Sent1, Sent2], [Sent3, Sent4]] + :param batch_size: Batch size for encoding + :param show_progress_bar: Output progress bar + :param num_workers: Number of workers for tokenization + :param activation_fct: Activation function applied on the logits output of the CrossEncoder. If None, nn.Sigmoid() will be used if num_labels=1, else nn.Identity + :param convert_to_numpy: Convert the output to a numpy matrix. + :param apply_softmax: If there are more than 2 dimensions and apply_softmax=True, applies softmax on the logits output + :param convert_to_tensor: Convert the output to a tensor. + :return: Predictions for the passed sentence pairs + """ + input_was_string = False + if isinstance(sentences[0], str): # Cast an individual sentence to a list with length 1 + sentences = [sentences] + input_was_string = True + + inp_dataloader = DataLoader( + sentences, + batch_size=batch_size, + collate_fn=self.smart_batching_collate_text_only, + num_workers=num_workers, + shuffle=False, + ) + + if show_progress_bar is None: + show_progress_bar = ( + logger.getEffectiveLevel() == logging.INFO or logger.getEffectiveLevel() == logging.DEBUG + ) + + iterator = inp_dataloader + if show_progress_bar: + iterator = tqdm(inp_dataloader, desc="Batches") + + if activation_fct is None: + activation_fct = self.default_activation_function + + pred_scores = [] + self.model.eval() + self.model.to(self._target_device) + with torch.no_grad(): + for features in iterator: + model_predictions = self.model(**features, return_dict=True) + logits = activation_fct(model_predictions.logits) + + if apply_softmax and len(logits[0]) > 1: + logits = torch.nn.functional.softmax(logits, dim=1) + pred_scores.extend(logits) + + if self.config.num_labels == 1: + pred_scores = [score[0] for score in pred_scores] + + if convert_to_tensor: + pred_scores = torch.stack(pred_scores) + elif convert_to_numpy: + pred_scores = np.asarray([score.cpu().detach().numpy() for score in pred_scores]) + + if input_was_string: + pred_scores = pred_scores[0] + + return pred_scores + + def rank( + self, + query: str, + documents: List[str], + top_k: Optional[int] = None, + return_documents: bool = False, + batch_size: int = 32, + show_progress_bar: bool = None, + num_workers: int = 0, + activation_fct=None, + apply_softmax=False, + convert_to_numpy: bool = True, + convert_to_tensor: bool = False, + ) -> List[Dict]: + """ + Performs ranking with the CrossEncoder on the given query and documents. Returns a sorted list with the document indices and scores. + + Example: + :: + + from sentence_transformers import CrossEncoder + model = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2") + + query = "Who wrote 'To Kill a Mockingbird'?" + documents = [ + "'To Kill a Mockingbird' is a novel by Harper Lee published in 1960. It was immediately successful, winning the Pulitzer Prize, and has become a classic of modern American literature.", + "The novel 'Moby-Dick' was written by Herman Melville and first published in 1851. It is considered a masterpiece of American literature and deals with complex themes of obsession, revenge, and the conflict between good and evil.", + "Harper Lee, an American novelist widely known for her novel 'To Kill a Mockingbird', was born in 1926 in Monroeville, Alabama. She received the Pulitzer Prize for Fiction in 1961.", + "Jane Austen was an English novelist known primarily for her six major novels, which interpret, critique and comment upon the British landed gentry at the end of the 18th century.", + "The 'Harry Potter' series, which consists of seven fantasy novels written by British author J.K. Rowling, is among the most popular and critically acclaimed books of the modern era.", + "'The Great Gatsby', a novel written by American author F. Scott Fitzgerald, was published in 1925. The story is set in the Jazz Age and follows the life of millionaire Jay Gatsby and his pursuit of Daisy Buchanan." + ] + + model.rank(query, documents, return_documents=True) + + :: + + [{'corpus_id': 0, + 'score': 10.67858, + 'text': "'To Kill a Mockingbird' is a novel by Harper Lee published in 1960. It was immediately successful, winning the Pulitzer Prize, and has become a classic of modern American literature."}, + {'corpus_id': 2, + 'score': 9.761677, + 'text': "Harper Lee, an American novelist widely known for her novel 'To Kill a Mockingbird', was born in 1926 in Monroeville, Alabama. She received the Pulitzer Prize for Fiction in 1961."}, + {'corpus_id': 1, + 'score': -3.3099542, + 'text': "The novel 'Moby-Dick' was written by Herman Melville and first published in 1851. It is considered a masterpiece of American literature and deals with complex themes of obsession, revenge, and the conflict between good and evil."}, + {'corpus_id': 5, + 'score': -4.8989105, + 'text': "'The Great Gatsby', a novel written by American author F. Scott Fitzgerald, was published in 1925. The story is set in the Jazz Age and follows the life of millionaire Jay Gatsby and his pursuit of Daisy Buchanan."}, + {'corpus_id': 4, + 'score': -5.082967, + 'text': "The 'Harry Potter' series, which consists of seven fantasy novels written by British author J.K. Rowling, is among the most popular and critically acclaimed books of the modern era."}] + + :param query: A single query + :param documents: A list of documents + :param top_k: Return the top-k documents. If None, all documents are returned. + :param return_documents: If True, also returns the documents. If False, only returns the indices and scores. + :param batch_size: Batch size for encoding + :param show_progress_bar: Output progress bar + :param num_workers: Number of workers for tokenization + :param activation_fct: Activation function applied on the logits output of the CrossEncoder. If None, nn.Sigmoid() will be used if num_labels=1, else nn.Identity + :param convert_to_numpy: Convert the output to a numpy matrix. + :param apply_softmax: If there are more than 2 dimensions and apply_softmax=True, applies softmax on the logits output + :param convert_to_tensor: Convert the output to a tensor. + :return: A sorted list with the document indices and scores, and optionally also documents. + """ + query_doc_pairs = [[query, doc] for doc in documents] + scores = self.predict( + query_doc_pairs, + batch_size=batch_size, + show_progress_bar=show_progress_bar, + num_workers=num_workers, + activation_fct=activation_fct, + apply_softmax=apply_softmax, + convert_to_numpy=convert_to_numpy, + convert_to_tensor=convert_to_tensor, + ) + + results = [] + for i in range(len(scores)): + if return_documents: + results.append({"corpus_id": i, "score": scores[i], "text": documents[i]}) + else: + results.append({"corpus_id": i, "score": scores[i]}) + + results = sorted(results, key=lambda x: x["score"], reverse=True) + return results[:top_k] From a459b1681b6fb2fc3093ce693dc38958b4c23945 Mon Sep 17 00:00:00 2001 From: micost Date: Wed, 22 May 2024 16:35:16 +0000 Subject: [PATCH 2/6] feat add cross encoder Signed-off-by: micost --- .vscode/launch.json | 1 + src/kimchima/__init__.py | 1 + src/kimchima/cmds/auto_cli.py | 44 ++++++++++++- src/kimchima/cmds/kimchima_cli.py | 4 +- src/kimchima/pkg/__init__.py | 2 + src/kimchima/pkg/cross_encoder_factory.py | 50 +++++--------- .../tests/test_cross_encoder_factory.py | 66 +++++++++++++++++++ 7 files changed, 130 insertions(+), 38 deletions(-) create mode 100644 src/kimchima/tests/test_cross_encoder_factory.py diff --git a/.vscode/launch.json b/.vscode/launch.json index a5463a5..3579158 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,7 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "name": "Auto - Debbug kimchima", "type": "debugpy", diff --git a/src/kimchima/__init__.py b/src/kimchima/__init__.py index 8243738..bc96193 100644 --- a/src/kimchima/__init__.py +++ b/src/kimchima/__init__.py @@ -30,6 +30,7 @@ ) __all__ = [ + 'CrossEncoderFactory', 'ModelFactory', 'TokenizerFactory', 'EmbeddingsFactory', diff --git a/src/kimchima/cmds/auto_cli.py b/src/kimchima/cmds/auto_cli.py index 5aa2fe7..83fa3c6 100644 --- a/src/kimchima/cmds/auto_cli.py +++ b/src/kimchima/cmds/auto_cli.py @@ -19,7 +19,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from kimchima.pkg import ModelFactory +from kimchima.pkg import ModelFactory, CrossEncoderFactory class CommandAutoModel: @@ -41,3 +41,45 @@ def auto(args): model = ModelFactory.auto_model(pretrained_model_name_or_path=args.model_name_or_path) print(model.config) +class CommandCrossEncoder: + """ + A class for loading models. + """ + + @staticmethod + def auto(args): + """ + Get embeddings of text. + + Args: + args (argparse.Namespace): The arguments. + + Returns: + torch.tensor: The embeddings of text. + """ + query = "A man is eating pasta." + + # With all sentences in the corpus + corpus = [ + "A man is eating food.", + "A man is eating a piece of bread.", + "The girl is carrying a baby.", + "A man is riding a horse.", + "A woman is playing violin.", + "Two men pushed carts through the woods.", + "A man is riding a white horse on an enclosed ground.", + "A monkey is playing drums.", + "A cheetah is running behind its prey.", + ] + model = CrossEncoderFactory('cross-encoder/ms-marco-MiniLM-L-6-v2') + sentence_combinations = [[query, sentence] for sentence in corpus] + scores = model.predict(sentence_combinations) + print(scores) + ranks = model.rank(query, corpus) + + # Print the scores + print("Query:", query) + for rank in ranks: + print(f"{rank['score']:.2f}\t{corpus[rank['corpus_id']]}") + + diff --git a/src/kimchima/cmds/kimchima_cli.py b/src/kimchima/cmds/kimchima_cli.py index a642568..603fec6 100644 --- a/src/kimchima/cmds/kimchima_cli.py +++ b/src/kimchima/cmds/kimchima_cli.py @@ -14,7 +14,7 @@ import argparse -from kimchima.cmds.auto_cli import CommandAutoModel +from kimchima.cmds.auto_cli import CommandCrossEncoder def main(): @@ -31,7 +31,7 @@ def main(): parser_auto=subparsers.add_parser("auto", help="auto help") parser_auto.add_argument("model_name_or_path", default="sentence-transformers/all-MiniLM-L6-v2", help="model name or path") parser_auto.add_argument("text", help="text str or list of text str") - parser_auto.set_defaults(func=CommandAutoModel.auto) + parser_auto.set_defaults(func=CommandCrossEncoder.auto) args = parser.parse_args() args.func(args) diff --git a/src/kimchima/pkg/__init__.py b/src/kimchima/pkg/__init__.py index 7d4fbaf..719afae 100644 --- a/src/kimchima/pkg/__init__.py +++ b/src/kimchima/pkg/__init__.py @@ -17,6 +17,7 @@ # module for the kimchima package. from .model_factory import ModelFactory +from .cross_encoder_factory import CrossEncoderFactory from .tokenizer_factory import TokenizerFactory from .embedding_factory import EmbeddingsFactory from .quantization_factory import QuantizationFactory @@ -27,6 +28,7 @@ __all__ = [ + 'CrossEncoderFactory', 'ModelFactory', 'TokenizerFactory', 'EmbeddingsFactory', diff --git a/src/kimchima/pkg/cross_encoder_factory.py b/src/kimchima/pkg/cross_encoder_factory.py index 9ccae5a..74d1c7d 100644 --- a/src/kimchima/pkg/cross_encoder_factory.py +++ b/src/kimchima/pkg/cross_encoder_factory.py @@ -1,24 +1,16 @@ -from functools import wraps - from transformers import AutoModelForSequenceClassification, AutoTokenizer, AutoConfig import numpy as np -import logging -import os -from typing import Dict, Type, Callable, List, Optional +from kimchima.pkg import logging +import platform +from typing import Dict, List, Optional import torch from torch import nn -from torch.optim import Optimizer from torch.utils.data import DataLoader -from tqdm.autonotebook import tqdm, trange -from transformers import is_torch_npu_available +from tqdm.autonotebook import tqdm from transformers.utils import PushToHubMixin -from .. import SentenceTransformer, util -from ..evaluation import SentenceEvaluator -from ..util import get_device_name - -logger = logging.getLogger(__name__) +logger=logging.get_logger(__name__) class CrossEncoderFactory(PushToHubMixin): @@ -62,7 +54,6 @@ def __init__( trust_remote_code: bool = False, revision: Optional[str] = None, local_files_only: bool = False, - default_activation_function=None, classifier_dropout: float = None, ): self.config = AutoConfig.from_pretrained( @@ -100,30 +91,19 @@ def __init__( self.max_length = max_length if device is None: - device = get_device_name() + if platform.system() == 'Darwin': + device='mps' + elif torch.cuda.is_available(): + device='cuda' + else: + device='cpu' logger.info("Use pytorch device: {}".format(device)) self._target_device = torch.device(device) - if default_activation_function is not None: - self.default_activation_function = default_activation_function - try: - self.config.sbert_ce_default_activation_function = util.fullname(self.default_activation_function) - except Exception as e: - logger.warning( - "Was not able to update config about the default_activation_function: {}".format(str(e)) - ) - elif ( - hasattr(self.config, "sbert_ce_default_activation_function") - and self.config.sbert_ce_default_activation_function is not None - ): - self.default_activation_function = util.import_from_string( - self.config.sbert_ce_default_activation_function - )() - else: - self.default_activation_function = nn.Sigmoid() if self.config.num_labels == 1 else nn.Identity() - - def smart_batching_collate_text_only(self, batch): + self.default_activation_function = nn.Sigmoid() if self.config.num_labels == 1 else nn.Identity() + + def _smart_batching_collate_text_only(self, batch): texts = [[] for _ in range(len(batch[0]))] for example in batch: @@ -171,7 +151,7 @@ def predict( inp_dataloader = DataLoader( sentences, batch_size=batch_size, - collate_fn=self.smart_batching_collate_text_only, + collate_fn=self._smart_batching_collate_text_only, num_workers=num_workers, shuffle=False, ) diff --git a/src/kimchima/tests/test_cross_encoder_factory.py b/src/kimchima/tests/test_cross_encoder_factory.py new file mode 100644 index 0000000..7359276 --- /dev/null +++ b/src/kimchima/tests/test_cross_encoder_factory.py @@ -0,0 +1,66 @@ +# coding=utf-8 +# Copyright [2024] [SkywardAI] +# 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 + +# http://www.apache.org/licenses/LICENSE-2.0 + +# 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 unittest + +from kimchima.pkg import ( + CrossEncoderFactory +) + +@unittest.skip("skip CrossEncoderFactory") +class TestCrossEncoderFactory(unittest.TestCase): + + encoder_name = 'cross-encoder/ms-marco-MiniLM-L-6-v2' + query = "A man is eating pasta." + + # With all sentences in the corpus + corpus = [ + "A man is eating food.", + "A man is eating a piece of bread.", + "The girl is carrying a baby.", + "A man is riding a horse.", + "A woman is playing violin.", + "Two men pushed carts through the woods.", + "A man is riding a white horse on an enclosed ground.", + "A monkey is playing drums.", + "A cheetah is running behind its prey.", + ] + + @classmethod + def setUpClass(cls): + cls.encoder = CrossEncoderFactory(cls.encoder_name) + + def test_predict(self): + """ + Test predict method + """ + + self.assertIsNotNone(self.encoder) + sentence_combinations = [[self.query, sentence] for sentence in self.corpus] + scores = self.encoder.predict(sentence_combinations) + + def test_rank(self): + """ + Test rank method + """ + + ranks = self.encoder.rank(self.query, self.corpus) + + # Print the scores + print("Query:", self.query) + for rank in ranks: + print(f"{rank['score']:.2f}\t{self.corpus[rank['corpus_id']]}") + + + From 8faa489dd47cd106f8d58328e64e26094098c987 Mon Sep 17 00:00:00 2001 From: micost Date: Wed, 22 May 2024 16:36:18 +0000 Subject: [PATCH 3/6] feat set kimchima_cli back Signed-off-by: micost --- src/kimchima/cmds/kimchima_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kimchima/cmds/kimchima_cli.py b/src/kimchima/cmds/kimchima_cli.py index 603fec6..a642568 100644 --- a/src/kimchima/cmds/kimchima_cli.py +++ b/src/kimchima/cmds/kimchima_cli.py @@ -14,7 +14,7 @@ import argparse -from kimchima.cmds.auto_cli import CommandCrossEncoder +from kimchima.cmds.auto_cli import CommandAutoModel def main(): @@ -31,7 +31,7 @@ def main(): parser_auto=subparsers.add_parser("auto", help="auto help") parser_auto.add_argument("model_name_or_path", default="sentence-transformers/all-MiniLM-L6-v2", help="model name or path") parser_auto.add_argument("text", help="text str or list of text str") - parser_auto.set_defaults(func=CommandCrossEncoder.auto) + parser_auto.set_defaults(func=CommandAutoModel.auto) args = parser.parse_args() args.func(args) From b72417cabe4bdcad768f984482ee3e810d475f9c Mon Sep 17 00:00:00 2001 From: micost Date: Wed, 22 May 2024 16:40:10 +0000 Subject: [PATCH 4/6] feat update test file Signed-off-by: micost --- src/kimchima/tests/test_cross_encoder_factory.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/kimchima/tests/test_cross_encoder_factory.py b/src/kimchima/tests/test_cross_encoder_factory.py index 7359276..fc8313d 100644 --- a/src/kimchima/tests/test_cross_encoder_factory.py +++ b/src/kimchima/tests/test_cross_encoder_factory.py @@ -49,6 +49,7 @@ def test_predict(self): self.assertIsNotNone(self.encoder) sentence_combinations = [[self.query, sentence] for sentence in self.corpus] scores = self.encoder.predict(sentence_combinations) + self.assertIsNotNone(scores) def test_rank(self): """ @@ -57,10 +58,7 @@ def test_rank(self): ranks = self.encoder.rank(self.query, self.corpus) - # Print the scores - print("Query:", self.query) - for rank in ranks: - print(f"{rank['score']:.2f}\t{self.corpus[rank['corpus_id']]}") + self.assertIsNotNone(ranks) From 21e4bae5ffd3b4de033d0c81a3931e81d61539de Mon Sep 17 00:00:00 2001 From: micost Date: Wed, 22 May 2024 16:40:54 +0000 Subject: [PATCH 5/6] feat update lauch.json Signed-off-by: micost --- .vscode/launch.json | 1 - 1 file changed, 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 3579158..a5463a5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,7 +4,6 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { "name": "Auto - Debbug kimchima", "type": "debugpy", From de6d1dc850d6ef5da40225753d8e5cb0fefb26c3 Mon Sep 17 00:00:00 2001 From: Rob Date: Thu, 23 May 2024 10:14:29 +0800 Subject: [PATCH 6/6] feat add linter Signed-off-by: Rob --- src/kimchima/pkg/cross_encoder_factory.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/kimchima/pkg/cross_encoder_factory.py b/src/kimchima/pkg/cross_encoder_factory.py index 74d1c7d..f26e066 100644 --- a/src/kimchima/pkg/cross_encoder_factory.py +++ b/src/kimchima/pkg/cross_encoder_factory.py @@ -12,6 +12,11 @@ logger=logging.get_logger(__name__) +""" +Original code from: https://github.com/UKPLab/sentence-transformers/blob/master/sentence_transformers/cross_encoder/CrossEncoder.py +Adapted by: Rob Zhang +Date: 20240523 +""" class CrossEncoderFactory(PushToHubMixin): """