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

Initial German support #69

Merged
merged 56 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f5758a6
first basic implementation of reference free - DE
ischender Dec 5, 2023
5f7efac
fizing tokenizers and adding a rougeL example
ischender Dec 5, 2023
34a6911
adding reference based German tests
ischender Dec 5, 2023
d2aa437
fixing tests, and fixing import bugs in DE
ischender Dec 5, 2023
20f02d3
Merge branch 'main' into de-support
ischender Dec 6, 2023
7fdbb58
adding notes re: case sensitivity
ischender Dec 6, 2023
e61da5b
removing autoformatting
ischender Dec 6, 2023
a0824e4
Merge branch 'citadel-ai:main' into de-support
ischender Dec 19, 2023
07225f8
adapting source based reference from ZH
ischender Dec 19, 2023
f11bd02
fixing error in typing in python 3.8
ischender Dec 20, 2023
2b5cb31
fixing formatting issues
ischender Dec 20, 2023
d3634cd
adding source based tests + context_relevance
ischender Dec 20, 2023
5bb01b2
first implementation reference free, no tests
ischender Dec 20, 2023
a30d2b6
small fixes
ischender Dec 20, 2023
abfc265
style fixes
ischender Dec 20, 2023
0a4d6db
first round of tests for reference free
ischender Dec 26, 2023
08cdb4c
finalizing tests for reference free
ischender Dec 26, 2023
1cfe04b
Merge branch 'citadel-ai:main' into de-support
ischender Dec 27, 2023
4cb5628
Merge branch 'main' into de-support
ischender Jan 4, 2024
32baf5b
moving and unifying Detoxify to metrics from /de and /en
ischender Jan 9, 2024
f0795fd
fixing typos and commented out code from the PR
ischender Jan 9, 2024
1cbe428
Update src/langcheck/metrics/de/reference_based_text_quality.py
ischender Jan 9, 2024
306bbea
Update src/langcheck/metrics/de/reference_based_text_quality.py
ischender Jan 9, 2024
de3af68
Update src/langcheck/metrics/de/source_based_text_quality.py
ischender Jan 9, 2024
650d0ca
Update src/langcheck/metrics/de/source_based_text_quality.py
ischender Jan 9, 2024
6f5995a
adding translation to fluency check
ischender Jan 10, 2024
35f08f7
adding test_tokenizers
ischender Jan 10, 2024
ef8b712
moving German model name for semantic similarity inside semantic_simi…
ischender Jan 10, 2024
63d1890
Merge branch 'de-support' of github.com:ischender/langcheck into de-s…
ischender Jan 10, 2024
ee79354
removing tokenizer parameters
ischender Jan 10, 2024
a12ca6e
fixing formatting
ischender Jan 10, 2024
71f2b62
fixing German sentence in `ai_disclaimer_similarity`
ischender Jan 10, 2024
117509a
fixing types
ischender Jan 10, 2024
47b4ee0
updated table for metrics
ischender Jan 10, 2024
8b52857
fixing types problems
ischender Jan 10, 2024
97468b3
fix notebook name
yosukehigashi Jan 11, 2024
14b549c
use de fluency
yosukehigashi Jan 11, 2024
458ec4d
fix docstring
yosukehigashi Jan 11, 2024
bdf638c
Update docs/metrics.md
ischender Jan 11, 2024
e154723
German documentation + screenshots
ischender Jan 11, 2024
285752a
adding German (ドイツ語???) to the Japanese documentation
ischender Jan 11, 2024
b8a1b8e
Merge branch 'de-support' of github.com:ischender/langcheck into de-s…
ischender Jan 11, 2024
a419d2b
adding a translation function to wrap up longer texts
ischender Jan 17, 2024
09adbc9
translating factual consistency data
ischender Jan 17, 2024
443ca7b
fixing translation wrapper
ischender Jan 17, 2024
0dca8ba
fixing translation wrapper
ischender Jan 17, 2024
4eb0676
moving translation wrapper to a file, adding tests
ischender Jan 17, 2024
bf5cd21
removing debugging print statements
ischender Jan 17, 2024
7a3fbff
format json documents
yosukehigashi Jan 18, 2024
d2a7acf
changes from PR comments
ischender Jan 18, 2024
cacf3bf
Update src/langcheck/metrics/de/_translation.py
ischender Jan 18, 2024
2e79a93
fixing flake8 formatting issue
ischender Jan 18, 2024
8ea3a4f
Merge branch 'de-support' of https://github.com/ischender/langcheck i…
yosukehigashi Jan 18, 2024
2c66b5a
small corrections to make pyright happy
ischender Jan 18, 2024
82b947f
changing block size as per PR suggestion
ischender Jan 18, 2024
e21a2d7
updating comment to describe min block size
ischender Jan 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,303 changes: 2,302 additions & 1 deletion benchmarking/data/qags_cnndm-de.json

Large diffs are not rendered by default.

2,303 changes: 2,302 additions & 1 deletion benchmarking/data/qags_xsum-de.json

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions src/langcheck/metrics/de/_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,30 @@ def _translate(self, texts: str) -> str:
tokenization = self._translation_pipeline.tokenizer(
texts, return_tensors="pt") # type: ignore
if tokenization.input_ids.shape[1] > (self._max_length / 2):
blocks = floor(
tokenization.input_ids.shape[1] / self._max_length) + 3
# Split the text into blocks, if it is too long
# adding 2 blocks to avoid problems with long texts
# NB: this comes from a few 100 tests, but it is not a science
blocks = floor(2 * tokenization.input_ids.shape[1] /
self._max_length)
sentences = sent_tokenize(texts)
# Split sentences into a number of blocks, e.g., 2 blocks = 2 groups
len_block = floor(len(sentences) / blocks) + 1
sentences_list = []
for i in range(blocks):
sentences_list.append(sentences[i * len_block:(i + 1) *
len_block])
texts_ = [" ".join(sent) for sent in sentences_list]
text_list = [" ".join(sent) for sent in sentences_list]
else:
texts_ = [texts]
texts_en = []
for text in texts_:
text_list = [texts]
translated_texts = []
for text in text_list:
text_en = [
str(d['translation_text']) # type: ignore
for d in self._translation_pipeline(text) # type: ignore
]
texts_en.append(" ".join(text_en))
text_en_final = " ".join(texts_en)
return text_en_final
translated_texts.append(" ".join(text_en))
text_translated_final = " ".join(translated_texts)
return text_translated_final

def __call__(self, text: str) -> str:
'''Translate the text using the translation pipeline.
Expand Down
3 changes: 3 additions & 0 deletions src/langcheck/metrics/de/source_based_text_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def factual_consistency(
], ('Unsupported model type. '
'The supported ones are ["local", "openai", "azure_openai"]')

# The English prompt works well enough for German, like with Japanese
# TODO: Investigate performance improvement with German prompt / translation
if model_type == 'openai' or model_type == 'azure_openai':
metric_value = en_factual_consistency(generated_outputs, sources,
prompts, model_type,
Expand All @@ -96,6 +98,7 @@ def factual_consistency(
en_generated_outputs = [
translation(gen_out) for gen_out in generated_outputs
]

# Compute the factual consistency scores in English.
factual_consistency_scores = en_factual_consistency(
generated_outputs=en_generated_outputs, sources=en_source).metric_values
Expand Down
Loading