Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NER-project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fsem25-project-nerds
NER-project
Commits
93d60fed
Commit
93d60fed
authored
1 month ago
by
Thomas Wolf
Browse files
Options
Downloads
Patches
Plain Diff
T5 NEC
parent
4d8d5696
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/common_interface.py
+1
-1
1 addition, 1 deletion
src/common_interface.py
src/experiments/NER_with_T5.py
+0
-12
0 additions, 12 deletions
src/experiments/NER_with_T5.py
src/models/T5.py
+20
-4
20 additions, 4 deletions
src/models/T5.py
with
21 additions
and
17 deletions
src/common_interface.py
+
1
−
1
View file @
93d60fed
...
...
@@ -5,7 +5,7 @@ Makes evaluating models easier.
from
src.models.llms_interface
import
available_models
as
llms
from
src.models.GLiNER
import
find_entities
as
find_entities_gliner
from
src.models.GLiNER
import
classify_entity
as
classify_entity_gliner
from
src.
experiments.NER_with_
T5
import
classify_entity
as
classify_entity_t5
from
src.
models.
T5
import
classify_entity
as
classify_entity_t5
from
src.experiments.NER_with_LLMs.NER_with_LLMs
import
find_entities
as
find_entities_llm
...
...
This diff is collapsed.
Click to expand it.
src/experiments/NER_with_T5.py
deleted
100644 → 0
+
0
−
12
View file @
4d8d5696
from
src.models.T5
import
infer_nli
def
classify_entity
(
sentence
,
entity
,
labels
):
print
(
"
classify entity
"
)
for
label
in
labels
:
print
(
f
"
Label:
{
label
}
"
)
hypothesis
=
f
"
{
entity
}
is a
{
label
}
"
result
=
infer_nli
(
sentence
,
hypothesis
)
print
(
f
"
Hypothesis:
{
hypothesis
}
, Result:
{
result
}
"
)
# TODO: determine highest confidence prediction
return
labels
[
0
]
This diff is collapsed.
Click to expand it.
src/models/T5.py
+
20
−
4
View file @
93d60fed
...
...
@@ -3,7 +3,8 @@ from datasets import Dataset, DatasetDict
label_map
=
{
True
:
"
entailment
"
,
False
:
"
contradiction
"
}
model_name
=
"
google/t5_xxl_true_nli_mixture
"
# Use t5-base for testing because it is smaller
model_name
=
"
google-t5/t5-base
"
# google/t5_xxl_true_nli_mixture
print
(
"
Loading model: T5 NLI
"
)
tokenizer
=
T5Tokenizer
.
from_pretrained
(
model_name
)
...
...
@@ -14,18 +15,33 @@ print("Finished loading model: T5 NLI")
def
infer_nli
(
premise
,
hypothesis
):
input_text
=
f
"
nli hypothesis:
{
hypothesis
}
premise:
{
premise
}
"
print
(
"
tokenize
"
)
#
print("tokenize")
inputs
=
tokenizer
(
input_text
,
return_tensors
=
"
pt
"
)
print
(
"
generate
"
)
#
print("generate")
output_ids
=
model
.
generate
(
**
inputs
)
print
(
"
decode
"
)
#
print("decode")
result
=
tokenizer
.
decode
(
output_ids
[
0
],
skip_special_tokens
=
True
)
return
result
def
classify_entity
(
sentence
,
entity
,
labels
):
best_label
=
None
for
label
in
labels
:
# rint(f"Label: {label}")
hypothesis
=
f
"
{
entity
}
is
{
label
}
"
result
=
infer_nli
(
sentence
,
hypothesis
)
# print(f"Hypothesis: {hypothesis}, Result: {result}")
if
result
==
"
entailment
"
:
return
label
# Return immediately if entailment is found
elif
result
==
"
neutral
"
and
best_label
is
None
:
best_label
=
label
# Store the first neutral label as a fallback
return
best_label
if
best_label
else
labels
[
0
]
def
preprocess_data
(
sample
):
input_text
=
f
"
nli hypothesis:
{
sample
[
'
hypothesis
'
]
}
premise:
{
sample
[
'
premise
'
]
}
"
target_text
=
label_map
[
bool
(
sample
[
'
entailment
'
])]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment