wanton7
Can someone give ideas how could I create optimal batches for Azure AI translator calls?
Limits are max 50000 characters max per batch and max 1000 strings per batch. Then there can be x amount destination languages that multiplies characters per language. So string with 100 characters will take space of 200 characters example if you use two destination languages. If you have one string with length 50000 you can only have destination language. These destination languages are defined per batch. So example if I had 6 destination languages I could split them to two batches of 3 languages each and so on.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 6 of 6 Posts
dimitarvp
What exactly are you asking? If you have a string of 50_000 characters and need 2 languages, that maybe your code should split it in two and then call the API, or what?
wanton7
How to make optimal batches with limit of 50000 characters/letters and 1000 strings per batch.
Making it optimal with one language wouldn’t be that bad but as there can be multiple languages and if you add another language it will multiple every string length added to the batch. Then because you have 50000 character limit you can’t example put 30000 long string into a batch with two languages because that will go over 50000 total character limit per batch as that one string is counted 60000 length string.
In some situations we have over 10 destination languages but how many destination languages depends on situation and can be pretty much anything from 1 to 20.
I tried to think how I could make optimal batches but my brain started to hurt badly so came here to ask help
Edit:
So example if I have 10 destination languages, 2500 strings and those string can be any length under 50000. How do I create optimal batches meaning minimum amount of API calls out of those when limit is 50000 total characters/letters and 1000 strings where every strings length (characters) count is multiplied with number of destination languages used per API call (batch).
dimitarvp
Yep, I get that, but what’s still missing in your question is how would you do it manually?
Would you:
Maybe I am misunderstanding you but it looks like trivial division would do the trick?
Or are you saying that e.g. if you have 2 x 5_000 length strings then you can still batch some other strings inside the same request?
wanton7
String can’t be splitted because they go AI translator. I mean if you split a string how it’s translated would change. I’m saying that if example had 5_000 length string I could translate it to 10 languages in one request. But one API call can only have specific destination languages so you can’t define destination languages per string.
So example if I have a string and 10 destination languages I can either use single API call with that string and set use all those 10 destination language to translate that string to 10 languages or I could do 10 API calls with single destination language. Example if string would have length of 25_000 I could only use two destination languages for one API call because with two languages that would be counted as 50_000 characters long that is the API total character limit.
Yes I can batch multiple strings into same request up to 1000 with any length but in total they can have up 50_000 characters. But every new destination language you add it will multiply length of all strings against that 50_000 limit. So with one language every string length is counted normally against 50_000 if you have two then every string length is doubled against that 50_000 and if you have three then every string length is tripled against that 50_000 limit.
dimitarvp
So maybe this?
Included:
requests_for_multiple_texts);benchmarkfunction (make a small new Elixir project and just includebencheein it, or useMix.installin a single.exsfile ) and you’ll see for yourself which of both is faster. SPOILERS: it’s the one usingEnum.reduce. I could probably make an even faster one but wasn’t in the mood to make one that uses only pure recursion and nothing else;The output might be slightly cryptic, so explaining it:
You get a list of tuples: first element is the text key (or the text itself), the second one is a list of lists of tuples.
The list of tuples represent a single request which might have e.g. same text with 5 languages. Each text here is represented by its length, not the key / text itself. Got tired and didn’t want to bloat the functions further with one more piece of data.
The list that encompasses that list of tuples is the list of requests that must be made for this single text to get fully translated.
Not sure if the code is good but it gets the job done. With the demo data above the result is:
…which means:
"text 1"gets to do 2 requests: one with 3 languages and one with 1 language;"text 2"gets to do 1 request with 2 languages;"text 3"gets to do 2 requests: one with 5 languages and one with 1 language.wanton7
Thank you!