Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add paragraph_threshold into paragraph_tokenize function #806

Merged
merged 2 commits into from
Jun 17, 2023

Conversation

pavaris-pm
Copy link
Contributor

@pavaris-pm pavaris-pm commented Jun 17, 2023

Adding paragraph_threshold argument, According to the original paper 'Where's the Point? Self-Supervised Multilingual Punctuation-Agnostic Sentence Segmentation,' we have the option to adjust the paragraph threshold using the paragraph_threshold argument. This threshold corresponds to the alpha value mentioned in the paper's method section. By default, the paragraph threshold is set to 0.5

α can be set to a small constant value such as 0.01, where a higher α gives rise to more conservative segmentation

Here is a usage:

when paragraph_threshold=0.5

from pythainlp.tokenize import paragraph_tokenize

sent = (
    "(1) บทความนี้ผู้เขียนสังเคราะห์ขึ้นมาจากผลงานวิจัยที่เคยทำมาในอดีต"
    +"  มิได้ทำการศึกษาค้นคว้าใหม่อย่างกว้างขวางแต่อย่างใด"
    +" จึงใคร่ขออภัยในความบกพร่องทั้งปวงมา ณ ที่นี้"
)

# same as paragraph_tokenize(sent, paragraph_threshold=0.5)
paragraph_tokenize(sent)

# output
# [['(1) '],
# ['บทความนี้ผู้เขียนสังเคราะห์ขึ้นมาจากผลงานวิจัยที่เคยทำมาในอดีต  ',
#  'มิได้ทำการศึกษาค้นคว้าใหม่อย่างกว้างขวางแต่อย่างใด ',
#  'จึงใคร่ขออภัยในความบกพร่องทั้งปวงมา ',
#  'ณ ที่นี้']]

when the paragraph_threshold = 0.8 -> more conservative segmentation

paragraph_tokenize(sent, paragraph_threshold=0.8)

# output
# [['(1) ',
#  'บทความนี้ผู้เขียนสังเคราะห์ขึ้นมาจากผลงานวิจัยที่เคยทำมาในอดีต  ',
#  'มิได้ทำการศึกษาค้นคว้าใหม่อย่างกว้างขวางแต่อย่างใด ',
#  'จึงใคร่ขออภัยในความบกพร่องทั้งปวงมา ',
#  'ณ ที่นี้']]

when the paragraph_threshold = 0.05 -> less conservative segmentation

paragraph_tokenize(sent, paragraph_threshold=0.05)

# output
# [['(1) '],
# ['บทความนี้ผู้เขียนสังเคราะห์ขึ้นมาจากผลงานวิจัยที่เคยทำมาในอดีต  '],
# ['มิได้ทำการศึกษาค้นคว้าใหม่อย่างกว้างขวางแต่อย่างใด ',
#  'จึงใคร่ขออภัยในความบกพร่องทั้งปวงมา '],
# ['ณ ที่นี้']]

@pavaris-pm pavaris-pm changed the title Test paragraph tokenize add parargraph_threshold into paragraph_tokenize function Jun 17, 2023
@pavaris-pm pavaris-pm closed this Jun 17, 2023
@pavaris-pm pavaris-pm changed the title add parargraph_threshold into paragraph_tokenize function add paragraph_threshold into paragraph_tokenize function Jun 17, 2023
@pavaris-pm pavaris-pm reopened this Jun 17, 2023
@sonarcloud
Copy link

sonarcloud bot commented Jun 17, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@pavaris-pm pavaris-pm changed the title add paragraph_threshold into paragraph_tokenize function add paragraph_threshold into paragraph_tokenize function Jun 17, 2023
Copy link
Member

@wannaphong wannaphong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pull request! 💯

@wannaphong wannaphong added this to the 4.1 milestone Jun 17, 2023
@wannaphong wannaphong linked an issue Jun 17, 2023 that may be closed by this pull request
@wannaphong wannaphong merged commit 61c6b8e into PyThaiNLP:dev Jun 17, 2023
9 of 12 checks passed
@wannaphong wannaphong mentioned this pull request Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add alpha value in wtpsplit
2 participants