Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load model from model-zoo #60

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions models/bert/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def evaluate_split(model, processor, tokenizer, args, split='dev'):

args.is_hierarchical = False
processor = dataset_map[args.dataset]()
pretrained_vocab_path = PRETRAINED_VOCAB_ARCHIVE_MAP[args.model]
tokenizer = BertTokenizer.from_pretrained(pretrained_vocab_path)
tokenizer = BertTokenizer.from_pretrained(args.model)

train_examples = None
num_train_optimization_steps = None
Expand All @@ -81,8 +80,8 @@ def evaluate_split(model, processor, tokenizer, args, split='dev'):
num_train_optimization_steps = int(
len(train_examples) / args.batch_size / args.gradient_accumulation_steps) * args.epochs

pretrained_model_path = args.model if os.path.isfile(args.model) else PRETRAINED_MODEL_ARCHIVE_MAP[args.model]
model = BertForSequenceClassification.from_pretrained(pretrained_model_path, num_labels=args.num_labels)
pretrained_model = args.model
model = BertForSequenceClassification.from_pretrained(pretrained_model, num_labels=args.num_labels)

if args.fp16:
model.half()
Expand Down Expand Up @@ -126,7 +125,7 @@ def evaluate_split(model, processor, tokenizer, args, split='dev'):
model = torch.load(trainer.snapshot_path)

else:
model = BertForSequenceClassification.from_pretrained(pretrained_model_path, num_labels=args.num_labels)
model = BertForSequenceClassification.from_pretrained(pretrained_model, num_labels=args.num_labels)
model_ = torch.load(args.trained_model, map_location=lambda storage, loc: storage)
state = {}
for key in model_.state_dict().keys():
Expand Down
3 changes: 2 additions & 1 deletion models/bert/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
def get_args():
parser = models.args.get_args()

parser.add_argument('--model', default=None, type=str, required=True)
parser.add_argument('--model', default=None, type=str, required=True,
choices=['bert-base-uncased','bert-large-uncased','bert-base-cased','bert-large-cased'])
parser.add_argument('--dataset', type=str, default='SST-2', choices=['SST-2', 'AGNews', 'Reuters', 'AAPD', 'IMDB', 'Yelp2014'])
parser.add_argument('--save-path', type=str, default=os.path.join('model_checkpoints', 'bert'))
parser.add_argument('--cache-dir', default='cache', type=str)
Expand Down