Coder Social home page Coder Social logo

Comments (10)

issam9 avatar issam9 commented on July 22, 2024 1

Great. I'll work on it

from langchain.

hwchase17 avatar hwchase17 commented on July 22, 2024 1

if you have any questions about the right place to put it or the conventions, happy to take a look at any even half-implemented stuff! just lmk

from langchain.

issam9 avatar issam9 commented on July 22, 2024

Would like to work on adding support for HF models. I think it is more convenient to use sentence_transformers as they can handle both sentence transformers and models coming from HF by adding a mean pooling layer. What do you think?

from langchain.

hwchase17 avatar hwchase17 commented on July 22, 2024

i think thats a great idea!

from langchain.

issam9 avatar issam9 commented on July 22, 2024

I made an initial implementation where i tried to stay close to how the openai one is implemented. Please check in the link below. I don't like the part where i instiatiate SentenceTransformer class inside embed functions and would love to have some suggestions there. Thanks

https://github.com/issam9/langchain/blob/issam/hf_embeddings/langchain/embeddings/huggingface.py

from langchain.

hwchase17 avatar hwchase17 commented on July 22, 2024

yeah the init is a little tricky. i dont love the way we do the initialization for other things, may try to rework that in the future. In the meantime, what about adding a classmethod and making it like:

@classmethod
def from_model_name(cls, model_name):
      import sentence tranformers
      model = sentence_transformers.SentenceTransformer(model_name)
      return cls(model)

thoughts?

from langchain.

hwchase17 avatar hwchase17 commented on July 22, 2024

am thinking of changing to use pydantic dataclasses to take advantage of the postinit stuff https://stackoverflow.com/questions/66571079/alter-field-after-instantiation-in-pydantic-basemodel-class

from langchain.

issam9 avatar issam9 commented on July 22, 2024

I tried doing that by overriding init which makes it possible to keep using BaseModel:

def __init__(self, **kw):
    super().__init__(**kw)
    try:
          import sentence_transformers

          self.client = sentence_transformers.SentenceTransformer(self.model_name)
    except ImportError:
          raise ValueError(
              "Could not import sentence_transformers python package. "
              "Please it install it with `pip install sentence_transformers`."
          )

from langchain.

hwchase17 avatar hwchase17 commented on July 22, 2024

yeah i dont hate that implementation either. id be down to do something like that as well. need to figure out longer term plan and unify across codebsase, but in short term im down to do it that way and see how well it works

from langchain.

issam9 avatar issam9 commented on July 22, 2024

Hi, I created a pull request with init override implementation. please lmk if i need to apply any changes

from langchain.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.