Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 25
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-J 25
22_23-J 25
Commits
4d8d6524
Commit
4d8d6524
authored
Mar 01, 2023
by
Ranodya M.J.C IT19987644
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
question and answer model ipynb file
parent
53c8618b
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
491 additions
and
50 deletions
+491
-50
backend/Question n Answering with KG.ipynb
backend/Question n Answering with KG.ipynb
+491
-0
backend/law_ai_qna.py
backend/law_ai_qna.py
+0
-50
No files found.
backend/Question n Answering with KG.ipynb
0 → 100644
View file @
4d8d6524
This diff is collapsed.
Click to expand it.
backend/law_ai_qna.py
deleted
100644 → 0
View file @
53c8618b
import
torch
import
numpy
as
np
import
pandas
as
pd
from
torch.utils.data
import
Dataset
from
transformers
import
TrainingArguments
,
Trainer
from
sklearn.model_selection
import
train_test_split
from
transformers
import
OpenAIGPTTokenizer
,
OpenAIGPTModel
data_path
=
'data/qna-summarization.xlsx'
df
=
pd
.
read_excel
(
data_path
)
Answers
=
df
[
'Answer'
]
.
tolist
()
Question
=
df
[
'Question'
]
.
tolist
()
tokenizer
=
OpenAIGPTTokenizer
.
from_pretrained
(
'openai-gpt'
)
tokenizer
.
add_special_tokens
({
'pad_token'
:
'[PAD]'
})
model
=
OpenAIGPTModel
.
from_pretrained
(
'openai-gpt'
)
question_encoding
=
tokenizer
(
Question
,
return_tensors
=
'pt'
,
padding
=
True
,
truncation
=
True
)
answer_encoding
=
tokenizer
(
Answers
,
return_tensors
=
'pt'
,
padding
=
True
,
truncation
=
True
)
class
QnADataset
(
Dataset
):
def
__init__
(
self
,
question_encoding
,
answer_encoding
):
self
.
question_encoding
=
question_encoding
self
.
answer_encoding
=
answer_encoding
def
__getitem__
(
self
,
idx
):
return
self
.
question_encoding
[
idx
],
self
.
answer_encoding
[
idx
]
def
__len__
(
self
):
return
len
(
self
.
question_encoding
)
dataset
=
QnADataset
(
question_encoding
,
answer_encoding
)
training_args
=
TrainingArguments
(
output_dir
=
'Question n Answering'
,
# output directory
num_train_epochs
=
1
,
# total # of training epochs
per_device_train_batch_size
=
100
,
# batch size per device during training
per_device_eval_batch_size
=
100
,
# batch size for evaluation
warmup_steps
=
500
,
# number of warmup steps for learning rate scheduler
weight_decay
=
0.01
,
# strength of weight decay
logging_dir
=
'Question n Answering/logs'
,
# directory for storing logs
logging_steps
=
10
)
trainer
=
Trainer
(
model
=
model
,
# the instantiated 🤗 Transformers model to be trained
args
=
training_args
,
# training arguments, defined above
train_dataset
=
dataset
# evaluation dataset
)
trainer
.
train
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment