MCPcopy Create free account
hub / github.com/BIT-DataLab/LakeBench / train

Function train

join/Deepjoin/train.py:14–55  ·  view source on GitHub ↗
(train_samples,dev_samples,model_save_path,model_name = 'all-mpnet-base-v2',
          train_batch_size = 16,num_epochs = 4,cpuid = 3)

Source from the content-addressed store, hash-verified

12
13
14def train(train_samples,dev_samples,model_save_path,model_name = 'all-mpnet-base-v2',
15 train_batch_size = 16,num_epochs = 4,cpuid = 3):
16 #### Just some code to print debug information to stdout
17 logging.basicConfig(format='%(asctime)s - %(message)s',
18 datefmt='%Y-%m-%d %H:%M:%S',
19 level=logging.INFO,
20 handlers=[LoggingHandler()])
21
22 #### model save path
23 model_save_path = 'output/deepjoin_webtable_training-'+model_name+'-'+datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
24
25 # load model
26 model = SentenceTransformer(model_name)
27
28 # set cuda
29 if cpuid==1:
30 os.environ["CUDA_VISIBLE_DEVICES"]= "1"
31 elif cpuid == 0:
32 os.environ["CUDA_VISIBLE_DEVICES"]= "0"
33 elif cpuid == 2:
34 device_ids = [0,1]
35 torch.cuda.set_device(device_ids[0])
36 model = DataParallel(model, device_ids=[0, 1])
37 model = model.module # 获取原始模型
38 else:
39 pass
40
41 # load data
42 train_dataloader = DataLoader(train_samples, shuffle=True, batch_size=train_batch_size)
43 train_loss = losses.MultipleNegativesRankingLoss(model=model)
44 evaluator = EmbeddingSimilarityEvaluator.from_input_examples(dev_samples)
45 #warmup_steps = math.ceil(len(train_dataloader) * num_epochs * 0.1)
46 warmup_steps = 10000
47
48 # train model
49 model.fit(train_objectives=[(train_dataloader, train_loss)],
50 evaluator=evaluator,
51 epochs=num_epochs,
52 evaluation_steps=1000,
53 warmup_steps=warmup_steps,
54 weight_decay=0.01,
55 output_path=model_save_path)
56
57# test
58

Callers 2

deepjoin_train.pyFile · 0.90
pretrain.pyFile · 0.85

Calls 1

DataLoaderClass · 0.90

Tested by

no test coverage detected