diff --git a/README.md b/README.md index c938569..3c590fe 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,6 @@ pip install transformers==3.3.1 # pip install happytransformer -U pip install --editable happy-transformer pip install tensorboardX -mkdir pred_results # Optional: # Install apex following https://github.com/NVIDIA/apex#linux @@ -39,13 +38,16 @@ pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cud For masked language models: ```bash +# folder for your personal results +mkdir pred_results + python src/mlm_predict.py bert-base \ data/test.core.masked.txt \ - results/bert-base.test.core.output.jsonl + pred_results/bert-base.test.core.output.jsonl python src/mlm_predict.py bert-base \ data/test.all.masked.txt \ - results/bert-base.test.all.output.jsonl + pred_results/bert-base.test.all.output.jsonl ``` Note that `bert-base` can be replaced by any model name in `[bert-base, bert-large, roberta-base, roberta-large]`. @@ -54,7 +56,7 @@ For left-to-right language models: ```bash python src/gpt_predict.py gpt \ data/test.core.masked.txt \ - results/gpt.test.core.output.jsonl + pred_results/gpt.test.core.output.jsonl ``` ### Fine-tune a MLM model @@ -77,10 +79,10 @@ CUDA_VISIBLE_DEVICES=0 python src/finetune_mlm.py \ ``` ```bash -python src/mlm_infer.py \ +python src/mlm_predict.py \ reload_bert:saved_models/finetuned_bert_large \ data/test.core.masked.txt \ - results/test.core.output.jsonl + pred_results/bert-large-finetuned.test.core.output.jsonl ``` ## Evaluation on Validation Set diff --git a/happy-transformer/happytransformer/happy_transformer.py b/happy-transformer/happytransformer/happy_transformer.py index 74b6283..adc85c2 100644 --- a/happy-transformer/happytransformer/happy_transformer.py +++ b/happy-transformer/happytransformer/happy_transformer.py @@ -90,7 +90,7 @@ def predict_mask(self, text: str, options=None, num_results=1): if self.mlm is None: self._get_masked_language_model() - if self.gpu_support: + if self.gpu_support == "cuda": self.mlm.to("cuda") if self.model_name in self.tag_one_transformers: @@ -251,7 +251,7 @@ def _get_prediction_softmax(self, text): # Convert inputs to PyTorch tensors tokens_tensor = torch.tensor([indexed_tokens]) - if self.gpu_support: + if self.gpu_support == "cuda": tokens_tensor = tokens_tensor.to('cuda') with torch.no_grad(): @@ -259,7 +259,7 @@ def _get_prediction_softmax(self, text): if self.model_name != "ROBERTA": segments_ids = self._get_segment_ids(text) segments_tensors = torch.tensor([segments_ids]) - if self.gpu_support: + if self.gpu_support == "cuda": segments_tensors = segments_tensors.to('cuda') outputs = self.mlm(tokens_tensor, token_type_ids=segments_tensors) else: diff --git a/src/gpt_predict.py b/src/gpt_predict.py index 32fb889..472f125 100644 --- a/src/gpt_predict.py +++ b/src/gpt_predict.py @@ -15,7 +15,7 @@ model_str = sys.argv[1] input_filename = sys.argv[2] output_filename = sys.argv[3] - cuda = True + cuda = torch.cuda.is_available() # TRUE if NVIDIA GPU is available model = None if model_str.startswith("reload_"): if model_str.startswith("reload_bert"):