• by simonw on 7/16/2024, 2:36:40 AM

    This is the code that does the work: https://github.com/rectanglehq/Shapeshift/blob/d954dab2a866c...

    There are a few ways this could be made a less expensive to run:

    1. Cache those embeddings somewhere. You're only embedding simple strings like "name" and "address" - no need to do that work more than once in an entire lifetime of running the tool.

    2. As suggested here https://news.ycombinator.com/item?id=40973028 change the design of the tool so instead of doing the work it returns a reusable data structure mapping input keys to output keys, so you only have to run it once and can then use that generated data structure to apply the transformations on large amounts of data in the future.

    3. Since so many of the keys are going to have predictable names ("name", "address" etc) you could even pre-calculate embeddings for the 1,000 most common keys across all three embedding providers and ship those as part of the package.

    Also: in https://github.com/rectanglehq/Shapeshift/blob/d954dab2a866c... you're using Promise.map() to run multiple embeddings through the OpenAI API at once, which risks tripping their rate-limit. You should be able to pass the text as an array in a single call instead, something like this:

            const response = await this.openai!.embeddings.create({
              model: this.embeddingModel,
              input: texts,
              encoding_format: "float",
            });
            return response.data.map(item => item.embedding);
    
    https://platform.openai.com/docs/api-reference/embeddings/cr... says input can be a string OR an array - that's reflected in the TypeScript library here too: https://github.com/openai/openai-node/blob/5873a017f0f2040ef...

  • by WhatsName on 7/16/2024, 12:35:12 AM

    Maybe I'm not the target audience, but here are simple questions to the author or potential users:

    What about anything more complex like date of birth to age or the other way round? Also since we will inevitably incur costs, why not let a llm write a transformation rule for us?

  • by lordofmoria on 7/16/2024, 3:59:50 AM

    Since LLMs are bad at the null hypothesis (in this case, when a key does not exist in the source JSON), how does this prevent hallucinating transformations for missing keys?

  • by leobg on 7/16/2024, 6:55:27 PM

    The example could be handled with no machine learning at all. Just use a bag of words comparison with a subword tokenizer. And if you do need embeddings (to map synonyms/topics), fastText is faster, cheaper and runs locally. For hard cases, you can feed the source/target schemas to gpt-4o once to create a map - and then apply that one map to all instances.

  • by lukasb on 7/16/2024, 12:37:57 AM

    What is this for? The examples given could be handled deterministically. Is this for situations where you don't know JSON schemas in advance? What situations are those?

  • by henry700 on 7/16/2024, 2:36:01 AM

    Keep the bug generators going, we will need the jobs

  • by visarga on 7/16/2024, 6:05:43 AM

    This task in the most general form is better done with question answering prompt than embeds. How do you solve "Full Name" -> "First Name", "Last Name" with embeds? QA is the right level of abstraction for schema conversion tasks. And it's simple, just put the source JSON + target JSON schema in the prompt and ask for value extraction.

  • by yetanotherjosh on 7/16/2024, 6:53:51 AM

    So this identifies keys from source and target objects that are fuzzy synonyms and copies the values over. What is a real world use case for this? Add the fact that it's fuzzy and won't always work, so would require a great deal of extra effort in QA/testing (harder than just mapping the keys programmatically), and I'm puzzled.

  • by happy_bacon on 7/16/2024, 4:03:09 PM

    Here is an another DSL for implementing object model mappings: https://github.com/patleahy/lir

  • by benzguo on 7/16/2024, 1:25:38 PM

    Put together a quick version with an LLM, using Substrate: https://www.val.town/v/substrate/shapeshift

    I've turned the target object into a JSON schema, but you could probably generate that JSON schema pretty reliably using a codegen LLM.

  • by explaininjs on 7/16/2024, 5:24:29 AM

    What’d be really great is a codegen aspect. A non-negligible part of any data munching operation is “this input object has fields X, Y, Z and we need an output object with fields X, f(X), Y, f(Y,Z)”. This is something and LLM has a decent chance at being really quite good at.

  • by hendler on 7/16/2024, 8:19:01 AM

    Created a Rust version using devin.ai. (untested)

    https://github.com/HumanAssisted/shapeshift-rust