Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BA Timeline Summarization
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
kaiser
BA Timeline Summarization
Commits
c1692a7f
Commit
c1692a7f
authored
3 years ago
by
vvye
Browse files
Options
Downloads
Patches
Plain Diff
Make summarization undershoot the length constraint instead of overshooting
parent
8cafc46d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
summarization.py
+19
-3
19 additions, 3 deletions
summarization.py
with
19 additions
and
3 deletions
summarization.py
+
19
−
3
View file @
c1692a7f
...
...
@@ -21,7 +21,7 @@ def summarize(sentences, vectorizer, keywords, by_tokens, num_sentences, num_tok
else
:
return
len
(
selected_indices
)
<
round
(
num_sentences
)
while
remaining_indices
and
constraint
()
:
while
True
:
# if the summary already has sentences, calculate the current summary vector
if
selected_indices
:
...
...
@@ -44,16 +44,32 @@ def summarize(sentences, vectorizer, keywords, by_tokens, num_sentences, num_tok
similarities
[
i
]
=
cosine_similarity
(
candidate_summary_vector
,
centroid
)[
0
,
0
]
sorted_indices
=
sorted
(
remaining_indices
,
key
=
lambda
i
:
similarities
[
i
],
reverse
=
True
)
# go through all sentences in order from "best" (most similar to centroid) to "worst"
for
i
in
sorted_indices
:
# don't consider this sentence in the next round
remaining_indices
.
remove
(
i
)
sentence
=
sentences
[
i
]
if
not
any
([
kw
.
lower
()
in
sentence
[
'
text
'
].
lower
()
for
kw
in
keywords
]):
# if the sentence contains no keywords, skip it
if
not
any
([
kw
.
lower
()
in
sentence
s
[
i
]
[
'
text
'
].
lower
()
for
kw
in
keywords
]):
continue
# if the sentence is near-identical to the current summary, skip it
if
redundant
(
i
,
selected_indices
,
X
):
continue
# if the sentence would make the summary too long, skip it
if
by_tokens
:
if
sum
([
len
(
sentences
[
k
][
'
text
'
].
split
())
for
k
in
(
selected_indices
+
[
i
])])
>
round
(
num_tokens
):
continue
else
:
if
len
(
selected_indices
)
+
2
>
round
(
num_sentences
):
continue
# otherwise, select the sentence
selected_indices
.
append
(
i
)
break
# if there are still sentences left, repeat this step
if
remaining_indices
:
continue
return
[
sentences
[
i
][
'
text
'
]
for
i
in
selected_indices
]
...
...
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