Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PrecomputeCommentEmbeddings
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Lukas Steimann
PrecomputeCommentEmbeddings
Commits
d8d08fbb
Commit
d8d08fbb
authored
3 years ago
by
Jan Lukas Steimann
Browse files
Options
Downloads
Patches
Plain Diff
Inital commit
parents
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#64531
failed
3 years ago
Stage: test
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+6
-0
6 additions, 0 deletions
.gitignore
.gitlab-ci.yml
+9
-0
9 additions, 0 deletions
.gitlab-ci.yml
ComputeCommentEmbeddings.py
+23
-0
23 additions, 0 deletions
ComputeCommentEmbeddings.py
NewYorkTimesDataset.py
+45
-0
45 additions, 0 deletions
NewYorkTimesDataset.py
with
83 additions
and
0 deletions
.gitignore
0 → 100644
+
6
−
0
View file @
d8d08fbb
*.csv
__pycache__/
venv
NewYorkTimesComments/
.idea/
\ No newline at end of file
This diff is collapsed.
Click to expand it.
.gitlab-ci.yml
0 → 100644
+
9
−
0
View file @
d8d08fbb
image
:
"
python:3.7"
python_run
:
script
:
-
pip install flair
-
pip install torch
-
pip install pandas
-
python3 ComputeCommentEmbeddings.py
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ComputeCommentEmbeddings.py
0 → 100644
+
23
−
0
View file @
d8d08fbb
import
torch
from
flair.data
import
Sentence
from
flair.embeddings
import
TransformerDocumentEmbeddings
from
tqdm
import
tqdm
from
NewYorkTimesDataset
import
get_argument_list
def
compute_embedding
(
comments
:
dict
)
->
dict
:
for
article_id
in
tqdm
(
comments
.
keys
()):
embedding_model
=
TransformerDocumentEmbeddings
(
'
bert-large-uncased
'
,
fine_tune
=
False
)
for
comment
in
comments
[
article_id
]:
comment_embedding_sentence
=
Sentence
(
comment
[
"
commentBody
"
])
embedding_model
.
embed
(
comment_embedding_sentence
)
comment
[
"
embedding
"
]
=
comment_embedding_sentence
.
embedding
return
comments
if
__name__
==
'
__main__
'
:
comments
=
get_argument_list
(
path
=
""
,
filename
=
"
NewYorkTimesComments/CommentsApril2017_DEV.csv
"
)
comments
=
compute_embedding
(
comments
)
torch
.
save
(
comments
,
"
embedded_comments.pt
"
)
This diff is collapsed.
Click to expand it.
NewYorkTimesDataset.py
0 → 100644
+
45
−
0
View file @
d8d08fbb
from
typing
import
List
import
pandas
as
pd
def
read_article_from_dataset
(
path
:
str
,
filename
:
str
)
->
pd
.
DataFrame
:
return
pd
.
read_csv
(
path
+
filename
)[[
"
articleID
"
,
"
headline
"
,
"
keywords
"
]]
def
get_article_list
(
path
:
str
,
filename
:
str
)
->
dict
:
dataset
=
read_article_from_dataset
(
path
,
filename
)
return
{
article
.
articleID
:
article
for
article
in
list
(
dataset
.
itertuples
())}
def
read_arguments_from_dataset
(
path
:
str
,
filename
:
str
)
->
pd
.
DataFrame
:
return
pd
.
read_csv
(
path
+
filename
)[
[
"
commentID
"
,
"
commentBody
"
,
"
commentSequence
"
,
"
articleID
"
,
"
parentID
"
]]
def
get_argument_list
(
path
:
str
,
filename
:
str
)
->
dict
:
dataset
=
read_arguments_from_dataset
(
path
,
filename
)
article_argument_dict
=
{}
for
argument_tuple
in
dataset
.
itertuples
():
argument
=
{
"
commentID
"
:
argument_tuple
.
commentID
,
"
commentBody
"
:
argument_tuple
.
commentBody
,
"
commentSequence
"
:
argument_tuple
.
commentSequence
,
"
parentID
"
:
argument_tuple
.
parentID
}
if
argument_tuple
.
articleID
in
article_argument_dict
.
keys
():
article_argument_dict
[
argument_tuple
.
articleID
].
append
(
argument
)
else
:
article_argument_dict
[
argument_tuple
.
articleID
]
=
[
argument
]
return
article_argument_dict
def
get_discussion_for_article
(
arguments
:
List
)
->
dict
:
discussion
=
{}
for
argument
in
arguments
:
argument_parent_id
=
argument
[
"
parentID
"
]
if
argument_parent_id
in
discussion
.
keys
():
discussion
[
argument_parent_id
].
append
([
argument
[
"
commentID
"
],
argument
[
"
commentBody
"
]])
else
:
discussion
[
argument_parent_id
]
=
[[
argument
[
"
commentID
"
],
argument
[
"
commentBody
"
]]]
return
discussion
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