Onnx in Stream Products

6 min read
Jeroen L.
Jeroen L.
Published September 17, 2024

Onnx (Open Neural Network Exchange) is an open-source artificial intelligence ecosystem that has become a cornerstone of Stream's product offerings. This versatile and powerful tool enables the creation, training, and deployment of machine learning models across various platforms and frameworks, providing a unified approach to AI development and implementation.

At Stream, Onnx plays a pivotal role in enhancing our product ecosystem. By leveraging Onnx, we develop and implement sophisticated machine-learning models that significantly improve the functionality and performance of our services. This is particularly evident in areas such as content moderation, where AI-driven solutions are crucial, and user experience optimization, where personalized interactions are key to customer satisfaction.

Adopting Onnx aligns with Stream's commitment to innovation and technological advancement. It allows us to stay at the forefront of AI integration in our products, ensuring that we can rapidly adapt to new developments in machine learning and consistently deliver cutting-edge solutions to our clients.

Applications of Onnx in Stream Products

One of the primary applications of Onnx in Stream's products is in our moderation services. We utilize purpose-built machine learning models to evaluate content efficiently and accurately. These models, which were implemented through Onnx, allow us to maintain high standards of content quality across our platforms. The flexibility of Onnx enables us to fine-tune these models for specific use cases, ensuring that our moderation services are both powerful and adaptable to various content types and community standards.

Additionally, Stream offers integration with third-party providers on an opt-in basis, further expanding the capabilities of our moderation services. This flexibility allows our clients to choose the level of moderation that best suits their needs while maintaining the robustness provided by Onnx-based models. Onnx's interoperability makes these integrations seamless, allowing for a cohesive moderation ecosystem that can leverage multiple AI models and services.

Beyond moderation, Onnx is utilized in various other Stream products and features:

  • Recommendation Systems: Onnx models power our content recommendation engines, providing personalized suggestions to users based on their behavior and preferences.
  • Natural Language Processing: We use Onnx to implement NLP models for tasks such as sentiment analysis, language detection, and text classification in our chat and messaging products.
  • Image and Video Analysis: Onnx facilitates the deployment of computer vision models for tasks like object detection and image classification in our media-rich applications.
  • Anomaly Detection: Our security and fraud prevention systems utilize Onnx models to identify unusual patterns and potential threats in real time.

Benefits of Using Onnx

The implementation of Onnx in Stream's products brings several key benefits:

  • Improved accuracy in moderation results: Onnx models provide highly accurate content evaluation, reducing false positives and negatives in moderation tasks. This leads to a safer and more enjoyable user experience while minimizing the need for manual intervention.
  • Scalability across Stream's product line: Onnx's versatility allows us to deploy models across various products and services, ensuring consistency and efficiency. This scalability enables us to rapidly introduce AI-powered features across our entire product ecosystem, maintaining a unified approach to machine learning integration.
  • Enhanced user experience: By leveraging Onnx for tasks such as content recommendation and personalization, we can provide end-users with a more tailored and engaging experience. This leads to increased user satisfaction, higher engagement rates, and improved retention across our clients' platforms.
  • Interoperability and flexibility: Onnx's open standard allows for seamless integration with various AI frameworks and tools. This flexibility enables Stream to choose the best tools for each specific task while maintaining a consistent deployment pipeline.
  • Reduced development time: The ability to export and import models in the Onnx format significantly reduces the time required to move from model development to production deployment, accelerating our innovation cycle.

Implementation of Onnx in Go

Stream has chosen to implement Onnx using the Go programming language. This decision was driven by Go's performance characteristics, concurrency support, and its growing ecosystem in the field of machine learning. The process of implementing Onnx in Go involves several key steps:

  • Setting up the Onnx runtime in Go: This involves integrating the Onnx runtime library with our Go codebase, ensuring that we can efficiently load and execute Onnx models within our Go applications.
  • Loading Onnx models: We've developed robust mechanisms for loading Onnx models into memory, handling versioning, and managing model updates to ensure that our services always use the most up-to-date and accurate models.
  • Preprocessing input data: Before feeding data into our Onnx models, we perform necessary preprocessing steps such as resizing images, tokenizing text, or normalizing numerical data. This ensures that the input data matches the expected format of our models.
  • Running inference: We've optimized our inference pipeline to take full advantage of Go's concurrency features, allowing for efficient parallel processing of multiple inputs when possible.
  • Postprocessing output data: After inference, we interpret the model outputs and transform them into actionable results that can be used by our various services, such as moderation decisions or content recommendations.

Each step requires careful consideration and proper implementation to ensure optimal performance and accuracy. Our team continuously refines these processes to improve efficiency and adapt to new requirements.

Code Snippets

While specific code snippets would depend on the exact implementation and use case, here are some general examples of how Onnx might be used in Go:

go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main import ( "github.com/owulveryck/onnx-go" "github.com/owulveryck/onnx-go/backend/x/gorgonnx" "gorgonia.org/tensor" ) func main() { // Initializing Onnx runtime backend := gorgonnx.NewGraph() model := onnx.NewModel(backend) // Loading an Onnx model err := model.UnmarshalBinary(modelData) if err != nil { log.Fatalf("Error loading model: %v", err) } // Preparing input data input := tensor.New(tensor.WithShape(1, 3, 224, 224), tensor.WithBacking(inputData)) // Running inference err = backend.SetInput(0, input) if err != nil { log.Fatalf("Error setting input: %v", err) } err = backend.Run() if err != nil { log.Fatalf("Error running inference: %v", err) } // Processing output output, err := backend.GetOutput(0) if err != nil { log.Fatalf("Error getting output: %v", err) } // Further processing of output would depend on the specific model and use case }

This example demonstrates the basic flow of using Onnx in Go, from initializing the runtime to running inference and retrieving the output. In practice, our implementation includes additional error handling, logging, and optimization techniques to ensure robustness and efficiency in a production environment.

Best Practices and Optimization

When using Onnx in Go, it's important to consider several best practices:

  • Performance optimization: We utilize Go's concurrency features to parallelize inference when possible. This includes using goroutines for concurrent model execution and channels for efficient data passing between the preprocessing, inference, and postprocessing stages.
  • Error handling: We implement robust error handling to manage potential issues during model loading or inference. This includes graceful degradation strategies to ensure service continuity even in the face of model failures.
  • Logging: We maintain comprehensive logs to track model performance and identify potential issues. This includes monitoring inference times, input/output characteristics, and any anomalies in model behavior.
  • Model versioning: We've implemented a sophisticated system for managing and updating model versions. This ensures that we're always using the most up-to-date and accurate models while allowing for easy rollback in case of issues.
  • Caching: We implement intelligent caching strategies for model inputs and outputs to improve performance and reduce the need for redundant computations.
  • Resource management: We carefully manage system resources, including memory and CPU usage, to ensure optimal performance even under high load conditions.

These practices help us maintain a robust, efficient, and scalable Onnx implementation in our Go-based services.

Future Developments

Stream is committed to continually improving and expanding our use of Onnx. Future developments may include:

  • Expanding Onnx usage to new products and features within the Stream ecosystem, such as advanced analytics tools and predictive modeling services.
  • Optimizing our Go implementation for even better performance and resource utilization, including exploration of hardware acceleration options like GPU support.
  • Exploring new machine learning models and techniques that can be implemented via Onnx to enhance our services further, such as advanced natural language processing models for improved content understanding.
  • Developing tools for automated model retraining and deployment, allowing for more frequent updates to our AI capabilities.
  • Investigating the potential of federated learning techniques using Onnx, enabling privacy-preserving machine learning across distributed datasets.

These future directions will help Stream maintain its position at the forefront of AI-powered communication and content delivery services.

Conclusion

Onnx plays a vital role in Stream's product ecosystem, enabling us to deliver high-quality, intelligent services to our clients. By leveraging Onnx through our Go implementation, we can provide accurate content moderation, personalized user experiences, and scalable machine-learning solutions across our product line.

The integration of Onnx has enhanced our current offerings and opened up new possibilities for innovation and service expansion. It allows us to rapidly adapt to new developments in the field of AI and machine learning, ensuring that our products remain cutting-edge and competitive.

As we continue to develop and optimize our use of Onnx, we remain committed to pushing the boundaries of what's possible in content delivery and management. Onnx's flexibility and power, combined with Stream's innovative approach and expertise in Go development, position us to continue delivering cutting-edge solutions that meet the evolving needs of our clients and their users.

The journey with Onnx is ongoing and filled with exciting possibilities and challenges. As we move forward, we're confident that our investment in this technology will continue to yield significant benefits, enabling us to create more intelligent, efficient, and user-centric products that set new industry standards.