text stringlengths 1 93.6k |
|---|
parser.add_argument("--cache_dir", default="", type=str,
|
help="Where do you want to store the pre-trained models downloaded from s3")
|
parser.add_argument("--train_data_subset", type=int, default=-1,
|
help="If > 0: limit the training data to a subset of train_data_subset instances.")
|
parser.add_argument("--max_seq_length", default=128, type=int,
|
help="The maximum total input sequence length after tokenization. Sequences longer "
|
"than this will be truncated, sequences shorter will be padded.")
|
parser.add_argument("--do_lower_case", action='store_true',
|
help="Set this flag if you are using an uncased model.")
|
parser.add_argument("--per_gpu_train_batch_size", default=8, type=int,
|
help="Batch size per GPU/CPU for training.")
|
parser.add_argument("--num_train_epochs", default=3.0, type=float,
|
help="Total number of training epochs to perform.")
|
parser.add_argument('--logging_steps', type=int, default=50,
|
help="Log every X updates steps.")
|
parser.add_argument("--no_cuda", action='store_true',
|
help="Avoid using CUDA when available")
|
parser.add_argument('--overwrite_output_dir', action='store_true',
|
help="Overwrite the content of the output directory")
|
parser.add_argument('--overwrite_cache', action='store_true',
|
help="Overwrite the cached training and evaluation sets")
|
parser.add_argument('--seed', type=int, default=42,
|
help="random seed for initialization")
|
args = parser.parse_args()
|
if os.path.exists(args.output_dir) and os.listdir(
|
args.output_dir) and not args.overwrite_output_dir:
|
raise ValueError(
|
"Output directory ({}) already exists and is not empty. Use --overwrite_output_dir to overcome.".format(
|
args.output_dir))
|
# Create output directory if needed
|
if not os.path.exists(args.output_dir):
|
os.makedirs(args.output_dir)
|
with open(os.path.join(args.output_dir, 'run_args.txt'), 'w') as f:
|
f.write(json.dumps(args.__dict__, indent=2))
|
f.close()
|
device = torch.device("cuda" if torch.cuda.is_available() and not args.no_cuda else "cpu")
|
args.n_gpu = torch.cuda.device_count()
|
args.device = device
|
# Setup logging
|
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(name)s - %(message)s',
|
datefmt='%m/%d/%Y %H:%M:%S',
|
level=logging.INFO)
|
logger.warning("Device: %s, n_gpu: %s", device, args.n_gpu)
|
# Set seed
|
set_seed(args)
|
# Prepare GLUE task
|
args.task_name = args.task_name.lower()
|
if args.task_name not in processors:
|
raise ValueError("Task not found: %s" % (args.task_name))
|
processor = processors[args.task_name]()
|
args.output_mode = output_modes[args.task_name]
|
label_list = processor.get_labels()
|
num_labels = len(label_list)
|
args.model_type = args.model_type.lower()
|
config_class, model_class, tokenizer_class = MODEL_CLASSES[args.model_type]
|
config = config_class.from_pretrained(args.config_name if args.config_name else args.model_name_or_path,
|
num_labels=num_labels,
|
finetuning_task=args.task_name,
|
cache_dir=args.cache_dir if args.cache_dir else None)
|
tokenizer = tokenizer_class.from_pretrained(args.tokenizer_name if args.tokenizer_name else args.model_name_or_path,
|
do_lower_case=args.do_lower_case,
|
cache_dir=args.cache_dir if args.cache_dir else None)
|
model = model_class.from_pretrained(args.model_name_or_path,
|
from_tf=bool('.ckpt' in args.model_name_or_path),
|
config=config,
|
cache_dir=args.cache_dir if args.cache_dir else None)
|
model.to(args.device)
|
logger.info("Training/evaluation parameters %s", args)
|
train_dataset = load_and_cache_examples(args, args.task_name, tokenizer, evaluate=False)
|
if args.train_data_subset > 0:
|
train_dataset = Subset(train_dataset, list(range(min(args.train_data_subset, len(train_dataset)))))
|
compute_textemb(args, train_dataset, model)
|
if __name__ == "__main__":
|
main()
|
# <FILESEP>
|
from __future__ import print_function
|
import os, re, subprocess, shlex
|
from subprocess import Popen, PIPE
|
# Environment Variables
|
_home = os.getenv('HOME')
|
moduleshome = os.getenv('MODULESHOME')
|
modulespath = os.getenv('MODULESPATH')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.