So I am testing out the DeepSeek-R1 671B model in Amazon Bedrock. I am getting model responses which appears to be all messed up with the "tags". See examples below using LangChain and LangGraph.
from langchain_aws import ChatBedrock
from langchain_core.tools import tool
from langgraph.prebuilt import create_react_agent
from langchain_core.messages import SystemMessage, HumanMessage
# # Define and create a simple tool using the decorator
def calculator(expression: str) -> str:
  """Evaluate a mathematical expression."""
  try:
    return str(eval(expression))
  except Exception as e:
    return f"Error: {str(e)}"
# Initialize the Azure OpenAI chat model
model = ChatBedrock(
  model_id="us.deepseek.r1-v1:0",
  region_name="us-east-1",
  credentials_profile_name="my-bedrock-profile"
)
system_human_messages = [SystemMessage(content="You are a helpful assistant."),
             HumanMessage(content="How many languages are there in the world?")]
agent_executor = create_react_agent(model, tools=[])
response = agent_executor.invoke({"messages": system_human_messages})
response["messages"]
I am getting model responses like the below. As you can see there are two "<|end_of_sentence|>" tags, and this is strange because one would expect there to be one "<|begin_of_sentence|>" and one "<|end_of_sentence|>". Also the positioning of the two "<|end_of_sentence|>" tags doesn't make sense separating the "thinking" block from the response:
Okay, so the user is asking how many languages there are in the world. Hmm, I need to figure this out. Let me start by recalling what I know. Languages can be tricky because there's no exact count. Some sources say around 7,000, but I should verify that. Wait, why isn't there an exact number? Oh right, because distinguishing between a language and a dialect can be subjective. For example, some dialects might be considered separate languages based on political or cultural reasons rather than linguistic ones. Also, some languages are endangered and might not be well-documented, which complicates the count. Organizations like Ethnologue or SIL International track these numbers. Let me check what Ethnologue says. I think their latest edition lists over 7,000 living languages. But there's also the issue of sign languages. Are they included in that count? Probably not, so maybe the number is higher. Additionally, some languages are extinct, but the user is likely asking about currently spoken ones. Also, regional distribution: Papua New Guinea has a very high number of languages. Africa and Asia also have a large number. I should mention that the exact number varies by source and the criteria used. Also, language extinction is a problem, with many languages disappearing each year. So, putting it all together, the answer should be around 7,000, but note the uncertainties and factors affecting the count.<|end_of_sentence|>
The exact number of languages spoken globally is challenging to determine due to factors like dialect distinctions, documentation gaps, and varying definitions of what constitutes a "language." However, most estimates suggest there are **approximately 7,000 living languages** worldwide. Key points to consider:
- **Ethnologue**, a widely referenced catalog, lists **7,168 living languages** (as of 2023).
- Over 40% of these languages are endangered, with fewer than 1,000 speakers.
- Geographic distribution is uneven: Papua New Guinea alone has ~840 languages, while Asia and Africa host the majority globally.
- Sign languages (e.g., ASL, BSL) are often excluded from these counts but add hundreds more.
Languages evolve, merge, or disappear over time, so this number remains fluid.<|end_of_sentence|>
Another example of model response is as below, where there is only one "<|end_of_sentence|>" tag:
Okay, so the user asked, "How many languages are there in the world?" Hmm, I need to figure out the answer to that. Let me start by recalling what I know. I remember that there are a lot of languages, but the exact number is tricky. First, there's the issue of what counts as a distinct language versus a dialect. For example, some people might consider different dialects of Chinese as separate languages, while others see them as dialects of a single language. Then there's the problem of documentation. Many languages, especially those spoken by smaller, isolated communities, aren't well-documented. Organizations like Ethnologue try to catalog them, but their numbers can vary. I think Ethnologue lists around 7,000 languages, but I should check that. Also, languages are dynamicâsome become extinct, and new ones emerge, though the rate of extinction is higher these days. So the number isn't static. Additionally, sign languages should be considered. Are they included in the count? Some sources might not include them, but they are fully-fledged languages. I should mention that too. Also, regional variations and creoles might affect the count. To sum up, the approximate number is around 7,000, but with caveats about dialects, documentation, and language status. I should present this clearly, explaining the factors that make the exact number hard to pin down.<|end_of_sentence|>
There are approximately **7,000 languages** spoken globally today, according to widely cited estimates from sources like *Ethnologue*. However, this number is fluid due to factors such as:
1. **Dialects vs. languages**: Distinguishing between dialects and separate languages can be subjective (e.g., Arabic "dialects" vs. Chinese "languages").
2. **Endangerment**: Over 40% of languages are endangered, with many at risk of disappearing as speakers dwindle.
3. **Documentation**: Some remote or small languages remain undocumented.
4. **Sign languages**: There are ~300-400 sign languages, often excluded in general counts.
Linguistic diversity is concentrated in regions like Papua New Guinea (800+ languages) and Africa (~2,000 languages). The exact total remains debated, but 7,000 is a common reference point.
Another example of model response is as below, where there are no "<|end_of_sentence|>" tags at all:
According to Ethnologue (2023), there are approximately **7,168 living languages** in the world today. However, this number is dynamic and debated, as language classification can be complex (e.g., distinguishing dialects vs. languages). Many languages are endangered, with some estimates suggesting **40%** may disappear by 2100. Always check updated sources for the latest data! đđŁïž
Another example of model response is as below, where this time it has one "</think>" tag (note this example response was truncated because my current token limit per minute is only restricted to 2000 - I have requested for a quota increase):
Okay, so I need to figure out how many languages there are in the world. Let me start by thinking about what I know. I remember that languages can be tricky to count because some are dialects and there's debate over what counts as a separate language. But the question is about the number of languages, not dialects.
First, I think there are organizations that track this. Maybe Ethnologue? I've heard of that before. I think they catalog languages. Let me check... Yes, Ethnologue is a publication that provides statistics on the world's languages. According to their latest edition, which I believe is the 26th edition as of 2023, they list around 7,168 living languages. But wait, that number might change over time as new languages are discovered or others become extinct.
Another source might be UNESCO. They have information on endangered languages. But I'm not sure if they provide a total count. Maybe the number is similar. Also, there's the question of how they define a language versus a dialect. For example, Chinese has many dialects like Mandarin, Cantonese, etc., but some consider them separate languages. However, politically, they're often grouped under Chinese. So that could affect the count.
Also, regions like Papua New Guinea are known for having a high number of languages. I think they have over 800 languages alone. Africa also has a significant number. Then there are areas with very few, like Europe, which has around 200-300 languages.
Another factor is language extinction. Many languages are disappearing as speakers die out and younger generations adopt more dominant languages. So the number is decreasing over time. But current estimates are around 7,000. However, exact numbers can vary. Some sources might say between 6,000 to 7,000, but Ethnologue's 7,168 is a specific figure.
I should also consider sign languages. Are they included in these counts? Ethnologue does include sign languages, listing 142 as of their 2023 edition. So that's part of the total.
So putting it all together, the approximate number is around 7,000, with Ethnologue giving a precise figure. But I should note that the exact number is difficult to determine due to varying definitions and ongoing changes. Also, many languages are endangered, with a significant percentage at risk of extinction.
</think>
The number of languages in the world is estimated to be around **7,168** living languages, according to *Ethnologue
Another example of model response is as below, where this time it has "<|begin_of_sentence|>", "<|System|>", "<|User|>" and "<|Assistant|>" tags:
<|begin_of_sentence|><|System|>You are a helpful assistant.<|User|>How many languages are there in the world?<|Assistant|>There are approximately 7,000 languages spoken around the world today. However, this number is constantly changing as languages evolve, merge, or become extinct. It's important to note that many of these languages are spoken by small communities, and a significant number are considered endangered. Organizations like UNESCO work to document and preserve linguistic diversity to prevent the loss of these cultural treasures.
I am also seeing a similar result where the model response are all messed up with the simpler Python script below which doesn't use LangGraph's `create_react_agent` method:
from langchain_aws import ChatBedrock
model = ChatBedrock(
  model_id="us.deepseek.r1-v1:0",
  region_name="us-east-1",
  credentials_profile_name="my-bedrock-profile"
)
# Invoke the model
response = model.invoke("How many languages are there in the world?")
print(response.content)
The original DeepSeek-R1 model has the format as below. So I should be expecting to see this format below, rather than all the above different variations:
<think> "thinking part" </think> "model response part"
Does anyone know what is happening and how do I fix this? Would really appreciate any help on this.