Live data from Hacker News

Show HN: Convert a number to an approximated text expression

github.com

11–20 of 32 posts

Re: Show HN: Convert a number to an approximated text expression

#11
post #3

One other aspect of approximated numbers is whether the author wants to emphasize that the number is large or small. "Less than" and "almost" carry different connotations.

You are right, hence Number Words returns different versions of the approximation: 'more', 'less' and 'around'. More nuanced versions could be added to the list. Importantly the choice of the approximation version to use would be with the user of the library. Wonder if the algorithm to choose appropriate approximation can be devised.

Given GP's "...whether the author wants to emphasize..." I don't think an algorithm could choose without knowing the author's intent. There's so much context and subtlety in choosing words based on intent.

Re: Show HN: Convert a number to an approximated text expression

#12
post #3

One other aspect of approximated numbers is whether the author wants to emphasize that the number is large or small. "Less than" and "almost" carry different connotations.

You are right, hence Number Words returns different versions of the approximation: 'more', 'less' and 'around'. More nuanced versions could be added to the list. Importantly the choice of the approximation version to use would be with the user of the library. Wonder if the algorithm to choose appropriate approximation can be devised.

> Water temperature is below 10C (input data would be 9.53C)

I can't tell the water temperature at all without context -- could be any temperature below 10C; and in the wrong context it could be confusing. "Just below"/"just under" would be a lot more accurate.

Re: Show HN: Convert a number to an approximated text expression

#13

One other aspect of approximated numbers is whether the author wants to emphasize that the number is large or small. "Less than" and "almost" carry different connotations.

Could one split the difference with "just under"? Or maybe add an expected value or prior value, and the algorithm would adjust how it is phrased?

Re: Show HN: Convert a number to an approximated text expression

#14
post #5

Earlier quoted context omitted.

I also wrote a function in Pascal to convert integers to natural language exactly. E.g. here is the output for 100000! https://gist.github.com/benibela/f0163b02562f647e4d2f

It's 8.8MB of plaintext English output describing the ridiculously long number, for those on mobile (who can't see the full file), or who don't want to click through the 'file is truncated...' link

As an approximation, one could just say three duoquinquagintacentillinonagintacentillion

Re: Show HN: Convert a number to an approximated text expression

#15
post #5

If you don't want it approximate, but exact, this is still a tricky non-trivial ambiguous problem. And this problem often comes up in text normalization for NLP task (e.g. speech recognition, or text-to-speech). For Python, for English, there is the inflect library: https://pypi.org/project/inflect/

I also wrote a function in Pascal to convert integers to natural language exactly. E.g. here is the output for 100000! https://gist.github.com/benibela/f0163b02562f647e4d2f

Isn't "one hundred thousand factorial" a more useful conversion? Would your conversion ever find utility?

Aside, this is why French style punctuation with a space before ? or ! is superior.

Re: Show HN: Convert a number to an approximated text expression

#16
post #8

What would be the intended use case for something like this?

Use automation to get human-friendly text for numbers. An example from the readme: - Q2 sales were around 1M$ When the input was $1,002,184.

I'd be amazed if a company put "around $1M" for anything that was "over $1M" !

Re: Show HN: Convert a number to an approximated text expression

#17

If you don't want it approximate, but exact, this is still a tricky non-trivial ambiguous problem. And this problem often comes up in text normalization for NLP task (e.g. speech recognition, or text-to-speech). For Python, for English, there is the inflect library: https://pypi.org/project/inflect/

Perl does a reasonable job of it in around 250 lines: https://github.com/neilb/Lingua-EN-Numbers/blob/master/lib/L...

Re: Show HN: Convert a number to an approximated text expression

#18

Earlier quoted context omitted.

Use automation to get human-friendly text for numbers. An example from the readme: - Q2 sales were around 1M$ When the input was $1,002,184.

I'd be amazed if a company put "around $1M" for anything that was "over $1M" !

They could use the -pr switch when running it.

Re: Show HN: Convert a number to an approximated text expression

#19

If you don't want it approximate, but exact, this is still a tricky non-trivial ambiguous problem. And this problem often comes up in text normalization for NLP task (e.g. speech recognition, or text-to-speech). For Python, for English, there is the inflect library: https://pypi.org/project/inflect/

For Common Lisp, there's a FORMAT directive:

  CL-USER> (format t "~r" 4096)
  four thousand ninety-six

Re: Show HN: Convert a number to an approximated text expression

#20
post #19

If you don't want it approximate, but exact, this is still a tricky non-trivial ambiguous problem. And this problem often comes up in text normalization for NLP task (e.g. speech recognition, or text-to-speech). For Python, for English, there is the inflect library: https://pypi.org/project/inflect/

For Common Lisp, there's a FORMAT directive: CL-USER> (format t "~r" 4096) four thousand ninety-six

I didn't know Common Lisp spoke American English
Post reply on HN