diff --git a/api-reference/openapi.json b/api-reference/openapi.json index 5e9c161b..5e06e939 100644 --- a/api-reference/openapi.json +++ b/api-reference/openapi.json @@ -1102,6 +1102,9 @@ "translation_memory_threshold": { "$ref": "#/components/schemas/TranslationMemoryThreshold" }, + "show_translation_memory_matches": { + "$ref": "#/components/schemas/ShowTranslationMemoryMatches" + }, "custom_instructions": { "description": "Specify a list of instructions to customize the translation behavior. Up to 10 custom instructions can be specified, each with a maximum of 300 characters.", "type": "array", @@ -1224,6 +1227,9 @@ "format": "uuid", "example": "3f1c9d0e-7a24-4b58-9c31-8f0e5d2a1b47" }, + "show_translation_memory_matches": { + "$ref": "#/components/schemas/ShowTranslationMemoryMatches" + }, "tag_handling": { "$ref": "#/components/schemas/TagHandlingOption" }, @@ -1318,6 +1324,53 @@ "v1" ], "example": "v2" + }, + "customizations": { + "description": "Details about the customizations applied to this text. Present if the `show_translation_memory_matches` parameter is set to true.", + "type": "object", + "properties": { + "translation_memory_matches": { + "description": "The translation memory segments that were integrated into the translated text, in text order.\nAn empty list means nothing from the translation memory reached the output.\nA stored segment that was found but not used does not appear.\n\nA fuzzy match that was adapted can be reported in several pieces.", + "type": "array", + "items": { + "type": "object", + "properties": { + "translation_memory_id": { + "$ref": "#/components/schemas/TranslationMemoryId" + }, + "segment_id": { + "description": "Identifier of the matched segment inside the translation memory.", + "type": "string", + "example": "8b1d5c2e-3f4a-4b6c-9d7e-0f1a2b3c4d5e" + }, + "match_score": { + "description": "Similarity between the source text and the matched segment, up to 100. 100 means the two are identical.", + "type": "number", + "example": 100 + }, + "text_ranges": { + "description": "Where the segment appears in `text`, as half-open ranges of Unicode code points:\n`start` is the index of the first code point and `end` is one past the last, as in\n[span ranges](/api-reference/quality-evaluations/poll#span-ranges). A range that\ndoes not start the text includes the whitespace before the segment.\nNot present when `tag_handling` is set, because positions cannot be mapped onto\nthe output with reinserted tags.", + "type": "array", + "items": { + "type": "object", + "properties": { + "start": { + "description": "Position of the first code point of the range.", + "type": "integer", + "example": 0 + }, + "end": { + "description": "Position after the last code point of the range.", + "type": "integer", + "example": 15 + } + } + } + } + } + } + } + } } } } @@ -11098,6 +11151,11 @@ "description": "When true, the response will include the billed_characters parameter, giving the\nnumber of characters from the request that will be counted by DeepL for billing purposes.", "type": "boolean" }, + "ShowTranslationMemoryMatches": { + "description": "When true, each translation includes a `customizations.translation_memory_matches` list with the\ntranslation memory segments that were integrated into the translated text and where they appear.\nRequires a translation memory on the request, set with `translation_memory_id` or linked through\n`style_profile_id`. A request with neither is rejected with `400 Bad Request`. If the style profile\nlinks no translation memory, the list is empty.\n\nAvailable on text translation only.\n\nSetting this parameter increases response time, so only set it when you use the result.", + "type": "boolean", + "default": false + }, "SplitSentencesOption": { "description": "Sets whether the translation engine should first split the input into sentences.\n\nPossible values are:\n * 0 - no splitting at all, whole input is treated as one sentence\n * 1 (default when tag_handling is not set to html) - splits on punctuation and on newlines\n * nonewlines (default when tag_handling=html) - splits on punctuation only, ignoring newlines", "type": "string", diff --git a/api-reference/openapi.yaml b/api-reference/openapi.yaml index db3e5b02..76db12a1 100644 --- a/api-reference/openapi.yaml +++ b/api-reference/openapi.yaml @@ -907,6 +907,8 @@ paths: $ref: '#/components/schemas/TranslationMemoryId' translation_memory_threshold: $ref: '#/components/schemas/TranslationMemoryThreshold' + show_translation_memory_matches: + $ref: '#/components/schemas/ShowTranslationMemoryMatches' custom_instructions: description: |- Specify a list of instructions to customize the translation behavior. Up to 10 custom instructions can be specified, each with a maximum of 300 characters. @@ -1040,6 +1042,8 @@ paths: type: string format: uuid example: 3f1c9d0e-7a24-4b58-9c31-8f0e5d2a1b47 + show_translation_memory_matches: + $ref: '#/components/schemas/ShowTranslationMemoryMatches' tag_handling: $ref: '#/components/schemas/TagHandlingOption' outline_detection: @@ -1120,7 +1124,53 @@ paths: - v2 - v1 example: v2 + customizations: + description: Details about the customizations applied to this text. + Present if the `show_translation_memory_matches` parameter is set to true. + type: object + properties: + translation_memory_matches: + description: |- + The translation memory segments that were integrated into the translated text, in text order. + An empty list means nothing from the translation memory reached the output. + A stored segment that was found but not used does not appear. + A fuzzy match that was adapted can be reported in several pieces. + type: array + items: + type: object + properties: + translation_memory_id: + $ref: '#/components/schemas/TranslationMemoryId' + segment_id: + description: Identifier of the matched segment inside the translation memory. + type: string + example: 8b1d5c2e-3f4a-4b6c-9d7e-0f1a2b3c4d5e + match_score: + description: Similarity between the source text and the matched segment, up to 100. + 100 means the two are identical. + type: number + example: 100 + text_ranges: + description: |- + Where the segment appears in `text`, as half-open ranges of Unicode code points: + `start` is the index of the first code point and `end` is one past the last, as in + [span ranges](/api-reference/quality-evaluations/poll#span-ranges). A range that + does not start the text includes the whitespace before the segment. + Not present when `tag_handling` is set, because positions cannot be mapped onto + the output with reinserted tags. + type: array + items: + type: object + properties: + start: + description: Position of the first code point of the range. + type: integer + example: 0 + end: + description: Position after the last code point of the range. + type: integer + example: 15 '400': $ref: '#/components/responses/BadRequest' '403': @@ -8349,6 +8399,19 @@ components: When true, the response will include the billed_characters parameter, giving the number of characters from the request that will be counted by DeepL for billing purposes. type: boolean + ShowTranslationMemoryMatches: + description: |- + When true, each translation includes a `customizations.translation_memory_matches` list with the + translation memory segments that were integrated into the translated text and where they appear. + Requires a translation memory on the request, set with `translation_memory_id` or linked through + `style_profile_id`. A request with neither is rejected with `400 Bad Request`. If the style profile + links no translation memory, the list is empty. + + Available on text translation only. + + Setting this parameter increases response time, so only set it when you use the result. + type: boolean + default: false SplitSentencesOption: description: |- Sets whether the translation engine should first split the input into sentences. diff --git a/docs/customize/overview.mdx b/docs/customize/overview.mdx index a6f79d03..fc9a210d 100644 --- a/docs/customize/overview.mdx +++ b/docs/customize/overview.mdx @@ -51,7 +51,7 @@ Here's when to use each customization feature for the best results. The [`contex Best practices for writing natural-language instructions that produce consistent results. - Retrieve your translation memories and control the matching threshold in translation requests. + Retrieve your translation memories, control the matching threshold, and see which parts of a translation came from them. Keep company terms, acronyms, and names transcribed correctly in Voice API sessions. diff --git a/docs/customize/using-style-profiles.mdx b/docs/customize/using-style-profiles.mdx index a2ca6feb..8a5e4d7c 100644 --- a/docs/customize/using-style-profiles.mdx +++ b/docs/customize/using-style-profiles.mdx @@ -75,7 +75,7 @@ A style profile replaces the individual customization parameters. A request that If the style profile doesn't exist or your account can't access it, `/v2/translate` returns `404 Not Found`. `/v2/document` accepts the upload and reports the error in the [document status](/api-reference/document/check-document-status) with the message `Style profile not found.`. -All `model_type` values are supported. Translation memories linked through a profile use the default matching threshold of 75. +All `model_type` values are supported. Translation memories linked through a profile use the default matching threshold of 75. To see which parts of a text translation came from the profile's translation memory, see [Using Translation Memories](/docs/customize/using-translation-memories#step-4-see-which-segments-came-from-the-translation-memory). ## Set the glossary priority diff --git a/docs/customize/using-translation-memories.mdx b/docs/customize/using-translation-memories.mdx index 44472d89..16791d8b 100644 --- a/docs/customize/using-translation-memories.mdx +++ b/docs/customize/using-translation-memories.mdx @@ -1,6 +1,6 @@ --- title: "Using Translation Memories" -description: "Learn how to retrieve your translation memories and use them in translation requests" +description: "Learn how to retrieve your translation memories, use them in translation requests, and see which parts of a translation came from them" covers: [Customize] public: true --- @@ -11,7 +11,7 @@ Translation memories store and reuse previously created translations. When you t ## What you'll learn -In this tutorial, we'll retrieve the translation memories on your account, use one in a translation request, and adjust the matching threshold to control how closely source text must match a stored segment. +In this tutorial, we'll retrieve the translation memories on your account, use one in a translation request, adjust the matching threshold to control how closely source text must match a stored segment, and see which parts of a translation came from the translation memory. ## Before you begin @@ -163,6 +163,58 @@ curl -X POST 'https://api.deepl.com/v2/translate' \ With a threshold of `100`, "Halloo Welt!" is no longer an exact match for "Hallo Welt!", so the translation memory segment is not applied. DeepL falls back to its default translation: "Hello world!". +## Step 4: See which segments came from the translation memory + +Finally, let's find out which parts of a translation came from the translation memory, for example so that only freshly translated text goes to human review. We'll send a text with two sentences, only the first of which is stored, and set `show_translation_memory_matches` to `true`. + +```sh +curl -X POST 'https://api.deepl.com/v2/translate' \ +--header 'Authorization: DeepL-Auth-Key [yourAuthKey]' \ +--header 'Content-Type: application/json' \ +--data '{ + "text": [ + "Hallo Welt! Wie geht es dir?" + ], + "target_lang": "EN", + "translation_memory_id": "a74d88fb-ed2a-4943-a664-a4512398b994", + "show_translation_memory_matches": true +}' +``` + +**Expected output:** + +```json +{ + "translations": [ + { + "detected_source_language": "DE", + "text": "Hello everyone! How are you?", + "customizations": { + "translation_memory_matches": [ + { + "translation_memory_id": "a74d88fb-ed2a-4943-a664-a4512398b994", + "segment_id": "8b1d5c2e-3f4a-4b6c-9d7e-0f1a2b3c4d5e", + "match_score": 100, + "text_ranges": [ + { "start": 0, "end": 15 } + ] + } + ] + } + } + ] +} +``` + +Each entry names the stored segment that was used, its match score, and the `text_ranges` it covers in `text`, counted in Unicode code points. Here, "Hello everyone!" (code points 0 up to, but not including, 15) came from the translation memory, while "How are you?" was freshly translated. An empty `translation_memory_matches` list means nothing from the translation memory reached the output. + +Two things to notice about ranges: + +- `end` is exclusive, so a range covers `text[start:end]` +- A range that does not start the text includes the whitespace before the segment. Trim it if you display or compare the ranged text. + +For the full behavior, including fuzzy matches, tag handling, and style profiles, see the [`show_translation_memory_matches` parameter reference](/api-reference/translate/request-translation#body-show-translation-memory-matches). + ## What you've accomplished You've learned how to: @@ -170,9 +222,11 @@ You've learned how to: - Retrieve the translation memories on your account - Use a translation memory in a translation request - Control the matching threshold to tune how closely source text must match a stored segment +- Find out which segments of a translation came from the translation memory ## See also - [List translation memories](/api-reference/translation-memory/list-translation-memories) — API reference - [Text translation endpoint](/api-reference/translate/request-translation#body-translation-memory-id) — `translation_memory_id` and `translation_memory_threshold` parameter reference +- [`show_translation_memory_matches` parameter](/api-reference/translate/request-translation#body-show-translation-memory-matches) on the text translation endpoint - [Supported languages](/docs/getting-started/supported-languages) — check which languages support translation memories diff --git a/docs/resources/roadmap-and-release-notes.mdx b/docs/resources/roadmap-and-release-notes.mdx index 83b16d52..e1b57926 100644 --- a/docs/resources/roadmap-and-release-notes.mdx +++ b/docs/resources/roadmap-and-release-notes.mdx @@ -9,6 +9,12 @@ rss: true +## November 26 - Translation Memory Matches in Text Translation +- A [translation memory](/docs/customize/using-translation-memories) reuses your stored translations for matching segments. [`POST /v2/translate`](/api-reference/translate/request-translation) can now report which stored segments made it into each translated text and where, so you can, for example, send only the freshly translated parts to human review. +- Set [`show_translation_memory_matches`](/api-reference/translate/request-translation#body-show-translation-memory-matches) to `true` on a request with a `translation_memory_id` or a `style_profile_id`. Each translation then returns `customizations.translation_memory_matches`, with the translation memory ID, segment ID, match score, and the `text_ranges` the segment covers in `text`, counted in Unicode code points. An empty list means nothing from the translation memory reached the output. +- `text_ranges` is omitted when `tag_handling` is set. A request without a translation memory or a style profile is rejected with `400 Bad Request`. +- See [See which segments came from the translation memory](/docs/customize/using-translation-memories#step-4-see-which-segments-came-from-the-translation-memory) for an example. + ## November 17 - Custom Date Ranges for Language Pair Reports - The language pair-level CSV export and the "Top language pairs" tab in your DeepL account now support custom date ranges of up to 63 days, in addition to the existing presets. Use a custom range to report on an exact period that the presets don't cover. - A custom range can include the current day. Data for the current day lags by a few hours, and only data through the previous UTC calendar day is guaranteed complete.