Spaces:
Sleeping
Sleeping
Commit
·
f643d55
1
Parent(s):
b63ef0b
fix errors
Browse files
app.py
CHANGED
@@ -106,7 +106,7 @@ def search(query: str) -> List[Dict[str, Any]]:
|
|
106 |
headers=headers,
|
107 |
params={"q": term, "num": 4}, # Tìm kiếm với 4 kết quả mỗi trang
|
108 |
timeout=5,
|
109 |
-
verify=
|
110 |
)
|
111 |
resp.raise_for_status()
|
112 |
soup = BeautifulSoup(resp.text, "html.parser")
|
@@ -323,15 +323,15 @@ CHECKPOINT_DIR = "./checkpoints"
|
|
323 |
if not os.path.exists(CHECKPOINT_DIR):
|
324 |
os.makedirs(CHECKPOINT_DIR)
|
325 |
|
326 |
-
# Tải Dataset
|
327 |
dataset = load_dataset('vntc/wiki-mini-corpus')
|
328 |
|
329 |
-
# Chia Dataset thành train và validation
|
330 |
split_dataset = dataset['train'].train_test_split(test_size=0.1, seed=42)
|
331 |
train_dataset = split_dataset['train']
|
332 |
validation_dataset = split_dataset['test']
|
333 |
|
334 |
-
# Tiền Xử Lý Văn Bản
|
335 |
def preprocess_function(examples):
|
336 |
passages = [passage.lower().strip() for passage in examples['passage']]
|
337 |
return {'passage': passages}
|
@@ -355,7 +355,7 @@ def tokenize_function(examples):
|
|
355 |
tokenized_train = processed_train.map(tokenize_function, batched=True)
|
356 |
tokenized_validation = processed_validation.map(tokenize_function, batched=True)
|
357 |
|
358 |
-
# Thêm trường 'labels'
|
359 |
def add_labels(examples):
|
360 |
examples['labels'] = examples['input_ids'].copy()
|
361 |
return examples
|
@@ -363,15 +363,15 @@ def add_labels(examples):
|
|
363 |
tokenized_train = tokenized_train.map(add_labels, batched=True)
|
364 |
tokenized_validation = tokenized_validation.map(add_labels, batched=True)
|
365 |
|
366 |
-
# Loại bỏ các cột không cần thiết
|
367 |
tokenized_train = tokenized_train.remove_columns(['passage'])
|
368 |
tokenized_validation = tokenized_validation.remove_columns(['passage'])
|
369 |
|
370 |
-
# Định dạng dữ liệu cho PyTorch
|
371 |
tokenized_train.set_format('torch')
|
372 |
tokenized_validation.set_format('torch')
|
373 |
|
374 |
-
# Tạo DatasetDict
|
375 |
final_dataset = {
|
376 |
'train': tokenized_train,
|
377 |
'validation': tokenized_validation
|
|
|
106 |
headers=headers,
|
107 |
params={"q": term, "num": 4}, # Tìm kiếm với 4 kết quả mỗi trang
|
108 |
timeout=5,
|
109 |
+
verify=True, # Xác minh SSL
|
110 |
)
|
111 |
resp.raise_for_status()
|
112 |
soup = BeautifulSoup(resp.text, "html.parser")
|
|
|
323 |
if not os.path.exists(CHECKPOINT_DIR):
|
324 |
os.makedirs(CHECKPOINT_DIR)
|
325 |
|
326 |
+
# Tải Dataset
|
327 |
dataset = load_dataset('vntc/wiki-mini-corpus')
|
328 |
|
329 |
+
# Chia Dataset thành train và validation
|
330 |
split_dataset = dataset['train'].train_test_split(test_size=0.1, seed=42)
|
331 |
train_dataset = split_dataset['train']
|
332 |
validation_dataset = split_dataset['test']
|
333 |
|
334 |
+
# Tiền Xử Lý Văn Bản
|
335 |
def preprocess_function(examples):
|
336 |
passages = [passage.lower().strip() for passage in examples['passage']]
|
337 |
return {'passage': passages}
|
|
|
355 |
tokenized_train = processed_train.map(tokenize_function, batched=True)
|
356 |
tokenized_validation = processed_validation.map(tokenize_function, batched=True)
|
357 |
|
358 |
+
# Thêm trường 'labels'
|
359 |
def add_labels(examples):
|
360 |
examples['labels'] = examples['input_ids'].copy()
|
361 |
return examples
|
|
|
363 |
tokenized_train = tokenized_train.map(add_labels, batched=True)
|
364 |
tokenized_validation = tokenized_validation.map(add_labels, batched=True)
|
365 |
|
366 |
+
# Loại bỏ các cột không cần thiết
|
367 |
tokenized_train = tokenized_train.remove_columns(['passage'])
|
368 |
tokenized_validation = tokenized_validation.remove_columns(['passage'])
|
369 |
|
370 |
+
# Định dạng dữ liệu cho PyTorch
|
371 |
tokenized_train.set_format('torch')
|
372 |
tokenized_validation.set_format('torch')
|
373 |
|
374 |
+
# Tạo DatasetDict
|
375 |
final_dataset = {
|
376 |
'train': tokenized_train,
|
377 |
'validation': tokenized_validation
|