Comments (3)
can you share the code u used?
from jsonformer.
from jsonformer import Jsonformer
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
tokenizer = AutoTokenizer.from_pretrained("StabilityAI/stablelm-base-alpha-7b")
model = AutoModelForCausalLM.from_pretrained("StabilityAI/stablelm-base-alpha-7b")
model.half().cuda()
json_schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number"},
"is_student": {"type": "boolean"},
"courses": {
"type": "array",
"items": {"type": "string"}
}
}
}
prompt = "Generate a person's information based on the following schema:"
jsonformer = Jsonformer(model, tokenizer, json_schema, prompt)
generated_data = jsonformer()
print(generated_data)
To alleviate this problem I have tried loading through:
model = AutoModelForCausalLM.from_pretrained("StabilityAI/stablelm-base-alpha-7b", device_map="auto", torch_dtype=torch.float16)
Which seems to load better but then I run into the following:
IndexError Traceback (most recent call last)
Cell In[10], line 23
21 prompt = "Generate a person's information based on the following schema:"
22 jsonformer = Jsonformer(model, tokenizer, json_schema, prompt)
---> 23 generated_data = jsonformer()
25 print(generated_data)
File /opt/conda/lib/python3.10/site-packages/jsonformer/main.py:188, in Jsonformer.__call__(self)
185 def __call__(self) -> Dict[str, Any]:
186 self.value = {}
--> 188 generated_data = self.generate_object(
189 self.json_schema["properties"], self.value
190 )
191 return generated_data
File /opt/conda/lib/python3.10/site-packages/jsonformer/main.py:114, in Jsonformer.generate_object(self, properties, obj)
109 def generate_object(
110 self, properties: Dict[str, Any], obj: Dict[str, Any]
111 ) -> Dict[str, Any]:
112 # self.debug("[generate_object] properties", properties)
113 for key, schema in properties.items():
--> 114 obj[key] = self.generate_value(schema, obj, key)
115 return obj
File /opt/conda/lib/python3.10/site-packages/jsonformer/main.py:136, in Jsonformer.generate_value(self, schema, obj, key)
134 new_array = []
135 obj[key] = new_array
--> 136 return self.generate_array(schema["items"], new_array)
137 elif schema_type == "object":
138 new_obj = {}
File /opt/conda/lib/python3.10/site-packages/jsonformer/main.py:146, in Jsonformer.generate_array(self, item_schema, obj)
144 def generate_array(self, item_schema: Dict[str, Any], obj: Dict[str, Any]) -> list:
145 for _ in range(self.max_array_length):
--> 146 element = self.generate_value(item_schema, obj)
147 obj[-1] = element
149 obj.append(self.generation_marker)
File /opt/conda/lib/python3.10/site-packages/jsonformer/main.py:131, in Jsonformer.generate_value(self, schema, obj, key)
129 return self.generate_boolean()
130 elif schema_type == "string":
--> 131 obj[key if key else -1] = self.generation_marker
132 return self.generate_string()
133 elif schema_type == "array":
IndexError: list assignment index out of range
from jsonformer.
@anujnayyar1 this should be fixed in the latest release, thanks!
from jsonformer.
Related Issues (20)
- Support for JSON-LD
- Make `Jsonformer` derive from `PreTrainedModel`
- Description of keys
- ctransformers / GGML support HOT 6
- Need to support Generation Config for model generation parameters
- allow for do_sample=True HOT 1
- High VRam Requirement HOT 3
- Json Former Causing High V-Memory Usage and Error with Increasing Token Size HOT 1
- Error in logits_processors.py - OutputNumbersTokens().__call__() for some models HOT 2
- Supporting InferenceClient
- AWQ RuntimeError HOT 2
- Documentation for returning an array of objects HOT 10
- Issue with array response HOT 1
- feature pairity with openai function calling
- Support for GPTQ models
- Support for LLaVa HOT 1
- compatibility with Gemini
- Infinite recursion bug when calling generate_number HOT 1
- How to specify a schema where an object can be any key-value combination
- Support nullable in case of not found sub object HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonformer.