Share and discover more about AI with social posts from the community.huggingface/OpenAi
Function Calling with GPT-4
As a basic example, let's say we asked the model to check the weather in a given location.

The LLM alone would not be able to respond to this request because it has been trained on a dataset with a cutoff point. The way to solve this is to combine the LLM with an external tool. You can leverage the function calling capabilities of the model to determine an external function to call along with its arguments and then have it return a final response. Below is a simple example of how you can achieve this using the OpenAI APIs.

Let's say a user is asking the following question to the model:

What is the weather like in London?

To handle this request using function calling, the first step is to define a weather function or set of functions that you will be passing as part of the OpenAI API request:

tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
},
}
]

The get_current_weather function returns the current weather in a given location. When you pass this function definition as part of the request, it doesn't actually executes a function, it just returns a JSON object containing the arguments needed to call the function. Here are some code snippets of how to achieve this.https://www.promptingguide.ai/applications/function_calling
Function Calling with LLMs
Getting Started with Function Calling

Function calling is the ability to reliably connect LLMs to external tools to enable effective tool usage and interaction with external APIs.

LLMs like GPT-4 and GPT-3.5 have been fine-tuned to detect when a function needs to be called and then output JSON containing arguments to call the function. The functions that are being called by function calling will act as tools in your AI application and you can define more than one in a single request.

Function calling is an important ability for building LLM-powered chatbots or agents that need to retrieve context for an LLM or interact with external tools by converting natural language into API calls.

Functional calling enables developers to create:

conversational agents that can efficiently use external tools to answer questions. For example, the query "What is the weather like in Belize?" will be converted to a function call such as get_current_weather(location: string, unit: 'celsius' | 'fahrenheit')
LLM-powered solutions for extracting and tagging data (e.g., extracting people names from a Wikipedia article)
applications that can help convert natural language to API calls or valid database queries
conversational knowledge retrieval engines that interact with a knowledge base
In this guide, we demonstrate how to prompt models like GPT-4 and open-source models to perform function calling for different use cases.https://www.promptingguide.ai/applications/function_calling
Hugging Face Space by GlidingDragonEntertainment

Let's create a simple Python app using FastAPI:

requirements.txt


fastapi
uvicorn[standard]
Hint You can also create the requirements file file directly in your browser.
app.py


from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def greet_json():
return {"Hello": "World!"}
Hint You can also create the app file file directly in your browser.
Create your Dockerfile:


# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
# you will also find guides on how best to write your Dockerfile

FROM python:3.9

RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

WORKDIR /app

COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt

COPY --chown=user . /app
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]

https://huggingface.co/spaces/GlidingDragonEntertainment/README Docker Spaces
LATAM Out-of-Distribution Few-shot Challenge
The LATAM Out-of-Distribution Few-shot Challenge is designed to push the boundaries of machine learning in autonomous driving applications. Participants will develop models that can classify unusual or specific vehicle types from minimal training data, a crucial skill in environments with unique vehicular regulations.

Challenge Description
Participants will utilize models initially trained on the ImageNet-1K dataset. The challenge involves fine-tuning these models using only six support images in a few-shot learning setup. The task is split into two distinct groups:

Easily Distinguishable Classes: For example, tuk-tuks, which are distinct from other vehicles in their appearance and function.
Sub-Groups of Common Classes: For example, fuel-transporting trucks, which require specific recognition due to unique regulatory requirements in traffic, such as maintaining a greater distance from these vehicles.
The goal is for models to effectively recognize and classify images into these specific categories with high precision, using the provided support set.

Key Challenge Details
Initial Training Data: Models will be pre-trained on the ImageNet-1K dataset.
Few-shot Learning: Fine-tuning with only six support images.
Application Focus: Autonomous driving, with emphasis on safety and regulatory compliance for specific vehicle types.
Allowed Techniques: Techniques that address out-of-distribution samples and adversarial training are permitted, provided that there's no exposure to the target domain.
Restrictions: The use of large language models (LLM) is prohibited due to the difficulty in verifying their training data domains.https://huggingface.co/spaces/Artificio/ROAM2FewShotChallenge ROAM2FewShotChallenge - a Hugging Face Space by Artificio
Introducing FLUX LoRA the Explorer 🧭

Explore, generate and download FLUX LoRAs! 🖼 Including the popular flux-realism and the cute Frosting Lane

Come over, we're just getting started
https://huggingface.co/spaces/multimodalart/flux-lora-the-explorer FLUX LoRa the Explorer - a Hugging Face Space by multimodalart
x Polars!

Polars now supports native reading from
@huggingface
datasets. Check out our latest blog to learn more about it:
https://pola.rs/posts/polars-hugging-face/ Hugging Face x Polars
Full shadcn PR is here!

All I did was take 10 components, add them to the sandbox, and send docs on how to use them to the LLM to generate code using them.

Definitely room for improving this approach and adding more components though!
https://github.com/Nutlope/llamacoder/pull/15
kobart-trans-en-ko-v2
This model was trained from scratch on the None dataset. It achieves the following results on the evaluation set:

Loss: 2.7926
Bleu: 5.3159
Model description
More information needed

Intended uses & limitations
More information needed

Training and evaluation data
More information needed

Training procedure
Training hyperparameters
The following hyperparameters were used during training:

learning_rate: 2e-05
train_batch_size: 32
eval_batch_size: 64
seed: 42
optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
lr_scheduler_type: linear
num_epochs: 3
Training results
Framework versions
Transformers 4.28.1
Pytorch 2.0.0
Datasets 2.12.0
Tokenizers 0.13.3
https://huggingface.co/dylanmengzhou/kobart-trans-en-ko-v2 dylanmengzhou/kobart-trans-en-ko-v2 · Hugging Face
Prompt Generator by ByteWave:
Welcome to the official repository of Prompt Generator, a powerful tool for effortlessly generating prompts for Large Language Models (LLMs) by ByteWave.

About Prompt Generator:
Prompt Generator is designed to streamline the process of generating text prompts for LLMs. Whether you are a content creator, researcher, or developer, this tool empowers you to create effective prompts quickly and efficiently.

Features:
Easy-to-use interface
Fast prompt generation
Customizable prompts for various LLMs
https://huggingface.co/ByteWave/prompt-generator ByteWave/prompt-generator · Hugging Face
ChatGPT Prompt Generator
This model is a fine-tuned version of BART-large on a ChatGPT prompts dataset. It achieves the following results on the evaluation set:

Train Loss: 2.8329
Validation Loss: 2.5015
Epoch: 4
Intended uses & limitations
You can use this to generate ChatGPT personas. Simply input a persona like below:

from transformers import BartForConditionalGeneration, BartTokenizer

example_english_phrase = "photographer"
batch = tokenizer(example_english_phrase, return_tensors="pt")
generated_ids = model.generate(batch["input_ids"], max_new_tokens=150)
output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)

Training procedure
Training hyperparameters
The following hyperparameters were used during training:

optimizer: {'name': 'AdamWeightDecay', 'learning_rate': 2e-05, 'decay': 0.0, 'beta_1': 0.9, 'beta_2': 0.999, 'epsilon': 1e-07, 'amsgrad': False, 'weight_decay_rate': 0.01}
training_precision: float32
https://huggingface.co/merve/chatgpt-prompts-bart-long merve/chatgpt-prompts-bart-long · Hugging Face
Model Card for Model ID
Overview This model is a conversational AI designed to engage in natural language interactions with users. It is based on the Causal Language Modeling (CLM) architecture and has been fine-tuned on conversational datasets to generate coherent and contextually relevant responses.

Usage To use this model, you can interact with it via the Hugging Face Inference API. Provide a text prompt, and the model will generate a response based on the given input.

Intended Use This model is intended for various conversational applications, including chatbots, virtual assistants, and dialogue systems. It can be deployed in environments where human-like interactions are required, such as customer service, educational platforms, or entertainment applications.

Limitations and Ethical Considerations While this model is capable of generating human-like responses, it may occasionally produce outputs that are inappropriate, offensive, or misleading. It is essential to monitor its responses and ensure responsible deployment to mitigate potential harms.

License The model is released under the Apache License 2.0, which allows for both commercial and non-commercial use with proper attribution.

Acknowledgments This model was trained using the Hugging Face Transformers library and fine-tuned on conversational datasets. We acknowledge the contributions of the open-source community and the developers of the Transformers library.

Contact Information For inquiries or feedback regarding this model, please contact [your contact information].

References Provide any relevant references, citations, or links to resources used in training or developing this model.
https://huggingface.co/VAIBHAV22334455/JARVIS VAIBHAV22334455/JARVIS · Hugging Face
chatgpt-gpt4-prompts-bart-large-cnn-samsum
This model generates ChatGPT/BingChat & GPT-3 prompts and is a fine-tuned version of philschmid/bart-large-cnn-samsum on an this dataset. It achieves the following results on the evaluation set:

Train Loss: 1.2214
Validation Loss: 2.7584
Epoch: 4
Streamlit
This model supports a Streamlit Web UI to run the chatgpt-gpt4-prompts-bart-large-cnn-samsum model:Open In HF Spaces

Training hyperparameters
The following hyperparameters were used during training:

optimizer: {'name': 'AdamWeightDecay', 'learning_rate': 2e-05, 'decay': 0.0, 'beta_1': 0.9, 'beta_2': 0.999, 'epsilon': 1e-07, 'amsgrad': False, 'weight_decay_rate': 0.01}
training_precision: float32
https://huggingface.co/Kaludi/chatgpt-gpt4-prompts-bart-large-cnn-samsum Kaludi/chatgpt-gpt4-prompts-bart-large-cnn-samsum · Hugging Face
Model Card for deberta-v3-base-prompt-injection
There is a newer version of the model - protectai/deberta-v3-base-prompt-injection-v2.

This model is a fine-tuned version of microsoft/deberta-v3-base on multiple combined datasets of prompt injections and normal prompts.

It aims to identify prompt injections, classifying inputs into two categories: 0 for no injection and 1 for injection detected.

It achieves the following results on the evaluation set:

Loss: 0.0010
Accuracy: 0.9999
Recall: 0.9997
Precision: 0.9998
F1: 0.9998
Model details
Fine-tuned by: Laiyer.ai
Model type: deberta-v3
Language(s) (NLP): English
License: Apache license 2.0
Finetuned from model: microsoft/deberta-v3-base
Intended Uses & Limitations
It aims to identify prompt injections, classifying inputs into two categories: 0 for no injection and 1 for injection detected.

The model's performance is dependent on the nature and quality of the training data. It might not perform well on text styles or topics not represented in the training set.
It took Google’s Transformer model from 2017 a whopping $900 to train. 💸

This in contrast to the $191 million Google spent on Gemini Ultra sounds like a bargain! 💰

Gemini Ultra required 50 billion petaFLOPS (one petaFLOP equals one quadrillion FLOPs). 🤖
Compared to OpenAI’s GPT-4, which required 21 billion petaFLOPS, at a cost of $78 million. 💡

2017: Original Transformer Model: $930 [@Google ] 💻
2018: BERT-Large: $3,288 [@Google] 📚
2019: RoBERTa Large: 160k [@Meta] 🌐
2020: GPT-3(175B): $4.32M [@OpenAI] 🧠
2023: Llama 2 70B: $3.93M [@Meta] 🐑
2023: GPT-4: $78.35M [@OpenAI] 🌟
Now, Gemini Ultra: $191.4M [@Google] 🚀

This forms an exponential curve! 🤯

But, why? 🤔
Compute, data, and expertise. All three come at a great cost! ⚙️📊💡

Google recently made Gemini-1.5-Flash fine-tuning free, as it's almost impossible for regular businesses to justify an in-house trained foundational model! 🆓

This barrier of cost is going to result in fewer new foundational models/less competition and more fine-tunes! 📉🔄

Data [Stanford University’s 2024 AI Index Report]: https://aiindex.stanford.edu/report/
Graphic: https://voronoiapp.com/technology/Googles-Gemini-Ultra-Cost-191M-to-Develop--1088

Many thanks to everyone spending tons of resources and open-sourcing the models! 🤗 Google’s Gemini Ultra Cost $191M to Develop ✨
Most LLMs are not reproducible because the underlying deep neural networks are not. Because that's something LLM creators don't care about. We do, and ours are reproducible, including our GenAI that uses GAN.

All you have to do is allow the user to specify the seeds of the random number generators involved. First, you need a good random generator you have full control over. Better than numpy.random. See ours, with infinite period and one line of code, faster and better than what's in Python and elsewhere. Here is the link: https://mltblog.com/4fGDLu0
Code now available for "Using Large Language Models for Hyperparameter Optimization" at https://github.com/michaelrzhang/LLM-HyperOpt 🚨

TLDR: You can just ask LLMs which hyperparameters to use, and it works pretty well! You can even directly optimize your model’s code as a hyperparameter with this.

Check out the paper at https://arxiv.org/abs/2312.04528 - with Michael Zhang, Nishkrit Desai, Juhan Bae, and Jimmy Ba
Multimodal CoT Prompting
Zhang et al. (2023) recently proposed a multimodal chain-of-thought prompting approach. Traditional CoT focuses on the language modality. In contrast, Multimodal CoT incorporates text and vision into a two-stage framework. The first step involves rationale generation based on multimodal information. This is followed by the second phase, answer inference, which leverages the informative generated rationales.

The multimodal CoT model (1B) outperforms GPT-3.5 on the ScienceQA benchmark.

MCOT
Image Source: Zhang et al. (2023)

Further reading:

Language Is Not All You Need: Aligning Perception with Language Models (Feb 2023)https://www.promptingguide.ai/techniques/multimodalcot
Nuanced feedback is required: Reflexion utilizes verbal feedback, which can be more nuanced and specific than scalar rewards used in traditional RL. This allows the agent to better understand its mistakes and make more targeted improvements in subsequent trials.

Interpretability and explicit memory are important: Reflexion provides a more interpretable and explicit form of episodic memory compared to traditional RL methods. The agent's self-reflections are stored in its memory, allowing for easier analysis and understanding of its learning process.

Reflexion is effective in the following tasks:

Sequential decision-making: Reflexion agents improve their performance in AlfWorld tasks, which involve navigating through various environments and completing multi-step objectives.
Reasoning: Reflexion improved the performance of agents on HotPotQA, a question-answering dataset that requires reasoning over multiple documents.
Programming: Reflexion agents write better code on benchmarks like HumanEval and MBPP, achieving state-of-the-art results in some cases.
Here are some limitations of Reflexion:

Reliance on self-evaluation capabilities: Reflexion relies on the agent's ability to accurately evaluate its performance and generate useful self-reflections. This can be challenging, especially for complex tasks but it's expected that Reflexion gets better over time as models keep improving in capabilities.
Long-term memory constraints: Reflexion makes use of a sliding window with maximum capacity but for more complex tasks it may be advantageous to use advanced structures such as vector embedding or SQL databases.
Code generation limitations: There are limitations to test-driven development in specifying accurate input-output mappings (e.g., non-deterministic generator function and function outputs influenced by hardware).
Figures source: Reflexion: Language Agents with Verbal Reinforcement Learninghttps://www.promptingguide.ai/techniques/reflexion
Reflexion
Reflexion is a framework to reinforce language-based agents through linguistic feedback. According to Shinn et al. (2023), "Reflexion is a new paradigm for ‘verbal‘ reinforcement that parameterizes a policy as an agent’s memory encoding paired with a choice of LLM parameters."

At a high level, Reflexion converts feedback (either free-form language or scalar) from the environment into linguistic feedback, also referred to as self-reflection, which is provided as context for an LLM agent in the next episode. This helps the agent rapidly and effectively learn from prior mistakes leading to performance improvements on many advanced tasks.

"Reflexion Framework"

As shown in the figure above, Reflexion consists of three distinct models:

An Actor: Generates text and actions based on the state observations. The Actor takes an action in an environment and receives an observation which results in a trajectory. Chain-of-Thought (CoT) and ReAct are used as Actor models. A memory component is also added to provide additional context to the agent.
An Evaluator: Scores outputs produced by the Actor. Concretely, it takes as input a generated trajectory (also denoted as short-term memory) and outputs a reward score. Different reward functions are used depending on the task (LLMs and rule-based heuristics are used for decision-making tasks).
Self-Reflection: Generates verbal reinforcement cues to assist the Actor in self-improvement. This role is achieved by an LLM and provides valuable feedback for future trials. To generate specific and relevant feedback, which is also stored in memory, the self-reflection model makes use of the reward signal, the current trajectory, and its persistent memory. These experiences (stored in long-term memory) are leveraged by the agent to rapidly improve decision-making.
In summary, the key steps of the Reflexion process are a) define a task, b) generate a trajectory, c) evaluate, d) perform reflection, and e) generate the next trajectory. The figure below demonstrates examples of how a Reflexion agent can learn to iteratively optimize its behavior to solve various tasks such as decision-making, programming, and reasoning. Reflexion extends the ReAct framework by introducing self-evaluation, self-reflection and memory components.

"Reflexion Examples"

Results
Experimental results demonstrate that Reflexion agents significantly improve performance on decision-making AlfWorld tasks, reasoning questions in HotPotQA, and Python programming tasks on HumanEval.

When evaluated on sequential decision-making (AlfWorld) tasks, ReAct + Reflexion significantly outperforms ReAct by completing 130/134 tasks using self-evaluation techniques of Heuristic and GPT for binary classification.

"Reflexion ALFWorld Results"

Reflexion significantly outperforms all baseline approaches over several learning steps. For reasoning only and when adding an episodic memory consisting of the most recent trajectory, Reflexion + CoT outperforms CoT only and CoT with episodic memory, respectively.

"Reflexion ALFWorld Results"

As summarized in the table below, Reflexion generally outperforms the previous state-of-the-art approaches on Python and Rust code writing on MBPP, HumanEval, and Leetcode Hard.

"Reflexion ALFWorld Results"

When to Use Reflexion?
Reflexion is best suited for the following:

An agent needs to learn from trial and error: Reflexion is designed to help agents improve their performance by reflecting on past mistakes and incorporating that knowledge into future decisions. This makes it well-suited for tasks where the agent needs to learn through trial and error, such as decision-making, reasoning, and programming.

Traditional reinforcement learning methods are impractical: Traditional reinforcement learning (RL) methods often require extensive training data and expensive model fine-tuning. Reflexion offers a lightweight alternative that doesn't require fine-tuning the underlying language model, making it more efficient in terms of data and compute resources.
%%capture
# update or install the necessary libraries
!pip install --upgrade openai
!pip install --upgrade langchain
!pip install --upgrade python-dotenv
!pip install google-search-results

# import libraries
import openai
import os
from langchain.llms import OpenAI
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from dotenv import load_dotenv
load_dotenv()

# load API keys; you will need to obtain these if you haven't yet
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
os.environ["SERPER_API_KEY"] = os.getenv("SERPER_API_KEY")


Now we can configure the LLM, the tools we will use, and the agent that allows us to leverage the ReAct framework together with the LLM and tools. Note that we are using a search API for searching external information and LLM as a math tool.

llm = OpenAI(model_name="text-davinci-003" ,temperature=0)
tools = load_tools(["google-serper", "llm-math"], llm=llm)
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)

Once that's configured, we can now run the agent with the desired query/prompt. Notice that here we are not expected to provide few-shot exemplars as explained in the paper.

agent.run("Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?")

The chain execution looks as follows:

> Entering new AgentExecutor chain...
I need to find out who Olivia Wilde's boyfriend is and then calculate his age raised to the 0.23 power.
Action: Search
Action Input: "Olivia Wilde boyfriend"
Observation: Olivia Wilde started dating Harry Styles after ending her years-long engagement to Jason Sudeikis — see their relationship timeline.
Thought: I need to find out Harry Styles' age.
Action: Search
Action Input: "Harry Styles age"
Observation: 29 years
Thought: I need to calculate 29 raised to the 0.23 power.
Action: Calculator
Action Input: 29^0.23
Observation: Answer: 2.169459462491557

Thought: I now know the final answer.
Final Answer: Harry Styles, Olivia Wilde's boyfriend, is 29 years old and his age raised to the 0.23 power is 2.169459462491557.

> Finished chain.

The output we get is as follows:

"Harry Styles, Olivia Wilde's boyfriend, is 29 years old and his age raised to the 0.23 power is 2.169459462491557."

We adapted the example from the LangChain documentation, so credit goes to them. We encourage the learner to explore different combination of tools and tasks.

You can find the notebook for this code here: https://github.com/dair-ai/Prompt-Engineering-Guide/blob/main/notebooks/react.ipynbhttps://www.promptingguide.ai/techniques/react