Skip to content

Extend Swedish TN - #468

Open
jimregan wants to merge 26 commits into
NVIDIA:staging/swe_tnfrom
jimregan:swedish-updates
Open

jimregan wants to merge 26 commits into
NVIDIA:staging/swe_tnfrom
jimregan:swedish-updates

Conversation

@jimregan

@jimregan jimregan commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Add a one line overview of what this PR aims to accomplish.

This incorporates additional items imported from Sardin, the open source version of the internal phonetisation system from MTM (Myndigheten för tillgängliga medier/Swedish Agency for Accessible Media)

Before your PR is "Ready for review"

Pre checks:

  • Have you signed your commits? Use git commit -s to sign.
  • Do all unittests finish successfully before sending PR?
    1. pytest or (if your machine does not have GPU) pytest --cpu from the root folder (given you marked your test cases accordingly @pytest.mark.run_only_on('CPU')).
    2. Sparrowhawk tests bash tools/text_processing_deployment/export_grammars.sh --MODE=test ...
  • If you are adding a new feature: Have you added test cases for both pytest and Sparrowhawk here.
  • Have you added __init__.py for every folder and subfolder, including data folder which has .TSV files?
  • Have you followed codeQL results and removed unused variables and imports (report is at the bottom of the PR in github review box) ?
  • Have you added the correct license header Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. to all newly added Python files?
  • If you copied nemo_text_processing/text_normalization/en/graph_utils.py your header's second line should be Copyright 2015 and onwards Google, Inc.. See an example here.
  • Remove import guards (try import: ... except: ...) if not already done.
  • If you added a new language or a new feature please update the NeMo documentation (lives in different repo).
  • Have you added your language support to tools/text_processing_deployment/pynini_export.py.

PR Type:

  • New Feature
  • Bugfix
  • Documentation
  • Test

If you haven't finished some of the above items you can still open "Draft" PR.

Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: "Christina Tånnander" <christina.tannander@mtm.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
@jimregan jimregan changed the title Plus / minus Extend Swedish TN Aug 7, 2026
pre-commit-ci Bot and others added 6 commits August 7, 2026 16:15
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
…ssing into swedish-updates

Signed-off-by: Jim O'Regan <joregan@kth.se>
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days.

@github-actions github-actions Bot added the Stale label Aug 22, 2026
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
@tbartley94

Copy link
Copy Markdown
Member

@jimregan Thanks for the contributions. Will be reviewing over next week, just sourcing language speakers to evaluate the test cases (you'll see additional reviewer beyond myself, they'll be going over the test cases).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The spoken expansion looks correct. Can we also cover the standard spelling e.Kr. (capital K and final period) if it isn't tested already?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added

~kl. 3
klockan tre
klass tre
~3 kl.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It may be worth considering an extra test case here. "3:e kl." is commonly used similarly to 3 kl.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

cwt centner
da atommassenhet
db decibel
dba decibel

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is dropping "A-vägd" for the trailing "a" intentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was inherited from Sardin (the open source version of MTM's normalisation system), fixed now

@j-l-thorsson j-l-thorsson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the Swedish test cases for language correctness, with TTS in mind. Left a few comments on written conventions and additional examples.

Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
@tbartley94
tbartley94 changed the base branch from main to staging/swe_tn September 25, 2026 19:21
@tbartley94

Copy link
Copy Markdown
Member

@jimregan doing technical review aspect, please let me know if any conflict with ongoing language changes.

@tbartley94 tbartley94 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Stylistic changes and implementation discussion. Need use of aliases instead of relying on f-string formatting in order to aid maintenance.

Comment thread nemo_text_processing/text_normalization/sv/data/abbreviations/__init__.py Outdated
@@ -11,8 +11,8 @@ mån måndag
mån månad
ons ons
ons onsdag
AB AB

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why wouldn't this be in abbreviations alternatives?

also can include the upper case variations.

@@ -22,4 +22,3 @@
Χ chi

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Honestly would just generate the unicode codepoints instead of adding file churn. Ditto for lower.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's mapping the characters to the Swedish version of their names. I don't see how generating unicode codepoints can achieve that.

@@ -9,6 +9,9 @@ celsiusgrad celsiusgrader
centimeter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sanity confirm: aware this transforms everything in the file to an fst mapping?

₧ peseta
ptas peseta
usd amerikansk dollar
us$ amerikansk dollar

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm, swedes add spacing at all after the currency or firmly non-delineated?

optional_minus_graph = pynini.closure(pynutil.insert("negative: ") + pynini.cross("-", "\"true\" "), 0, 1)

final_graph = optional_minus_graph + pynutil.insert("integer: \"") + self.graph + pynutil.insert("\"")
reference_graph = pynini.Fst()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rationale for building an empty fst? backend autocasts


graph_unit = pynini.string_file(get_abs_path("data/measure/unit.tsv"))
graph_unit_optional_dot = pynini.string_file(get_abs_path("data/measure/unit_optional_dot.tsv"))
graph_unit |= graph_unit_optional_dot + pynini.closure(pynutil.delete("."), 0, 1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't this just be two instances of the optional dot?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've renamed that to 'graph_optionally_dotted_units'

final_graph = (graph_integer_only + optional_delete_fractional_zeros) | graph_decimal

currency_quantity = pynini.string_file(get_abs_path("data/money/currency_quantity.tsv"))
amount = pynini.closure(NEMO_DIGIT | pynini.union(",", ".", "-", " "), 1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd just alias the strings as "PUNCTUATION" and NEMO_SPACE in the graph_utils. Avoids editing errors.

self.bare_ordinals = cleaned_graph
kapitlet_word = pynini.union("kapitlet", pynini.cross("kap", "kapitlet"))
kapitlet = cleaned_graph + NEMO_SPACE + kapitlet_word
reference_graph = pynini.Fst()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

curious about the reference_graph decision

optional_dot = pynini.closure(pynutil.delete("."), 0, 1) if written.isalpha() else pynini.accep("")
unit = pynutil.delete(written) + optional_dot
reference = reference_number + delete_space + unit
reference_graph |= reference + pynutil.insert(f" {definite}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

NEMO_SPACE with definite would be cleaner

Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
…ssing into swedish-updates

Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
Signed-off-by: Jim O'Regan <joregan@kth.se>
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.

5 participants