<?xml-model href='http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng' schematypens='http://relaxng.org/ns/structure/1.0'?><TEI xmlns="http://www.tei-c.org/ns/1.0">
	<teiHeader>
		<fileDesc>
			<titleStmt><title level='a'>EQUI-VOCAL: Synthesizing Queries for Compositional Video Events from Limited User Interactions</title></titleStmt>
			<publicationStmt>
				<publisher>VLDB Endowment</publisher>
				<date>07/01/2023</date>
			</publicationStmt>
			<sourceDesc>
				<bibl> 
					<idno type="par_id">10531462</idno>
					<idno type="doi">10.14778/3611479.3611482</idno>
					<title level='j'>Proceedings of the VLDB Endowment</title>
<idno>2150-8097</idno>
<biblScope unit="volume">16</biblScope>
<biblScope unit="issue">11</biblScope>					

					<author>Enhao Zhang</author><author>Maureen Daum</author><author>Dong He</author><author>Brandon Haynes</author><author>Ranjay Krishna</author><author>Magdalena Balazinska</author>
				</bibl>
			</sourceDesc>
		</fileDesc>
		<profileDesc>
			<abstract><ab><![CDATA[<p>We introduce EQUI-VOCAL: a new system that automatically synthesizes queries over videos from limited user interactions. The user only provides a handful of positive and negative examples of what they are looking for. EQUI-VOCAL utilizes these initial examples and additional ones collected through active learning to efficiently synthesize complex user queries. Our approach enables users to find events without database expertise, with limited labeling effort, and without declarative specifications or sketches. Core to EQUI-VOCAL's design is the use of spatio-temporal scene graphs in its data model and query language and a novel query synthesis approach that works on large and noisy video data. Our system outperforms two baseline systems---in terms of F1 score, synthesis time, and robustness to noise---and can flexibly synthesize complex queries that the baselines do not support.</p>]]></ab></abstract>
		</profileDesc>
	</teiHeader>
	<text><body xmlns="http://www.tei-c.org/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1">INTRODUCTION</head><p>Video data is increasingly becoming a prized commodity. Inexpensive large-scale video storage and advances in machine learning and computer vision have propelled the use of large video datasets with new applications including drone analytics <ref type="bibr">[75,</ref><ref type="bibr">77]</ref>, citywide traffic analytics <ref type="bibr">[2,</ref><ref type="bibr">26]</ref>, civil engineering <ref type="bibr">[4,</ref><ref type="bibr">25]</ref>, and many others <ref type="bibr">[24,</ref><ref type="bibr">52,</ref><ref type="bibr">58,</ref><ref type="bibr">67,</ref><ref type="bibr">69]</ref>. Although video database management systems (VDBMSs) have recently re-emerged as an active research area to support these applications <ref type="bibr">[3,</ref><ref type="bibr">5,</ref><ref type="bibr">17,</ref><ref type="bibr">23,</ref><ref type="bibr">39,</ref><ref type="bibr">40,</ref><ref type="bibr">49]</ref>, existing systems fall short of supporting many use cases. &#9675; a video dataset, 2 &#9675; user-defined functions that extract semantic information from videos, and 3  &#9675; a few user-provided labels, EQUI-VOCAL synthesizes a query to find instances of an event of interest. It iteratively 4  &#9675; asks the user for more labels to reduce its uncertainty. Once synthesized, it 5  &#9675; executes the query to return matching events on unseen videos.</p><p>Consider a traffic analytics application: A traffic engineer may want to understand road hazards involving car and motorcycle interactions (e.g., motorcycles swerving abruptly in front of turning cars). Although many computer vision models exist that detect common objects (e.g., "cars" and "motorcycles") <ref type="bibr">[78]</ref> and relate objects spatially (e.g., "bottom of", "left of", "near") <ref type="bibr">[12]</ref>, a specific classifier that identifies "a motorcycle swerving in front of a car, while the car is turning at an intersection" is unlikely to exist <ref type="bibr">[80,</ref><ref type="bibr">82]</ref>. Worse, training one would require many hours of user effort in labeling for a single query. Given the relative rarity of most interesting events, finding sufficient positive instances further exacerbates these labeling requirements. In our example, there will be many instances of cars and motorcycles in intersections. Only rarely would a motorcycle swerve in front of a turning car.</p><p>Assuming that we can run existing computer vision models on videos to identify objects, extract attributes, and reason about their pairwise relationships, some recent video data management systems support users by providing an interface to express a declarative query as a composition of extracted information <ref type="bibr">[7,</ref><ref type="bibr">11,</ref><ref type="bibr">14,</ref><ref type="bibr">23,</ref><ref type="bibr">49,</ref><ref type="bibr">54,</ref><ref type="bibr">80]</ref>. For example, a user might be able to query for an event using a specification that searches for video clips containing car and motorcycle objects, and specifying their desired relationships (near then front_of, etc.). These systems expect users to possess a level of database expertise to be able to express such queries. Additionally, real-world events can be difficult to express declaratively-even for experts. For example, there are multiple ways to express our sample query. The best way depends on the data (e.g., in a given video, motorcycles may be swerving from outside the frame, as illustrated in Figure <ref type="figure">2</ref>, discussed later). Other similar systems ask users to sketch their events <ref type="bibr">[10,</ref><ref type="bibr">14]</ref>; this is equally challenging for the same reason: an event of interest may deviate from the exact user-provided sketch.</p><p>In this paper, we present EQUI-VOCAL (Figure <ref type="figure">1</ref>), a system that addresses the above challenge by synthesizing declarative queries on behalf of users from a small number of labeled video segments. Put another way, EQUI-VOCAL Evolves Queries for Users Iteratively and is part of our larger VOCAL system <ref type="bibr">[19]</ref>. In our example, a user provides as few as two positive and ten negative examples containing the event of interest (see <ref type="bibr">Section 5)</ref>. EQUI-VOCAL then synthesizes a declarative query and executes it on the remaining large pool of video data to identify other examples of the desired event.</p><p>EQUI-VOCAL supports users' search for complex events without requiring any specific domain knowledge, with limited effort, and without requiring precise declarative specifications or sketches. Similar to other systems, we use the insight that while most user queries are new and unseen, they are usually composed of known, previously seen atoms. Computer vision models for common atoms already exist such as objects (e.g., "car", "backpack") and their spatial and semantic relationships (e.g., "left of", "holding"). Formally, such a composition of visual scenes is referred to as a scene graph in the computer vision community <ref type="bibr">[35,</ref><ref type="bibr">43]</ref> and was developed from its cognitive grounding in human perception <ref type="bibr">[8,</ref><ref type="bibr">46,</ref><ref type="bibr">83]</ref>. Key to EQUI-VOCAL's contribution is to encapsulate spatio-temporal scene graphs in its data model and use them to define a query language. A spatio-temporal scene graph conceptualizes the contents of a video as a sequence of graphs, each graph representing a single video frame. Each graph contains vertices, which represent objects in the frame; edges represent the relationships between those objects. Each object can possess a set of attributes that describe its properties (e.g., "red", "leather"). EQUI-VOCAL extracts relevant data from each video using user-provided functions: i.e., pre-existing detectors and classifiers; it synthesizes queries as a composition of extracted scene graph atoms. We show that EQUI-VOCAL's data model and query language, both based on the relational model, can express a variety of compositional queries.</p><p>Leveraging scene graphs, EQUI-VOCAL contributes a new query synthesis approach that finds user events with far fewer labeled examples than would be required to train a specialized machine learning model directly, and that works on noisy, video-scale data, and complex events. To support query synthesis in such environment, EQUI-VOCAL solves two technical challenges: it reduces computational effort and user effort.</p><p>EQUI-VOCAL reduces computational effort by limiting query search using scene graphs, by pruning search paths using beam search, and by avoiding expensive database operations. First, unlike prior query-by-example techniques that synthesize arbitrary SQL <ref type="bibr">[22,</ref><ref type="bibr">48,</ref><ref type="bibr">59,</ref><ref type="bibr">70,</ref><ref type="bibr">73]</ref>, EQUI-VOCAL reduces the search space by limiting the query search to sequences of scene graphs. Second, synthesizing queries over sequences of scene graphs can still be a computationally slow process to traverse the search space of possible queries. Existing query-by-example systems enumerate all possible queries; although pruning techniques like equivalence classes <ref type="bibr">[71]</ref>, over-approximation <ref type="bibr">[73]</ref>, and lifting projection operators <ref type="bibr">[70]</ref> can be used to reduce the search space, these mechanisms are not sufficient to make exhaustive exploration tractable. Instead, EQUI-VOCAL adopts a beam search strategy to explore the query space efficiently. Beam search limits exploration to a subset of the most promising branches at each step. Third, executing the many candidate queries on the user examples is prohibitively expensive. Existing systems <ref type="bibr">[70,</ref><ref type="bibr">73]</ref> evaluate candidate queries with many joins and thus do not scale well when the size of user examples becomes large. EQUI-VOCAL carefully generates efficient queries that avoid expensive operations such as recursive joins. EQUI-VOCAL comes with a set of optimizations to generate efficient SQL statements and uses the PostgreSQL database engine to execute them.</p><p>EQUI-VOCAL reduces user effort by using active learning and by being robust to noise. With active learning, EQUI-VOCAL reduces the number of labeled examples needed: Instead of asking a user to provide all examples up front, EQUI-VOCAL iteratively requests labels of carefully selected additional examples to reduce the uncertainty in query synthesis. Noise can naturally creep into systems that interface with user labeling, machine learning models, and potentially ambiguous real-world events. Distinct from other existing systems <ref type="bibr">[54,</ref><ref type="bibr">70]</ref>, EQUI-VOCAL searches for queries that best match potentially noisy data and input. It also retains imperfect query candidates at every iteration and uses regularization to prevent overfitting to noise or limited user input.</p><p>We evaluate our approach on synthetic and real datasets <ref type="bibr">[5,</ref><ref type="bibr">81]</ref> and show that it outperforms two baselines <ref type="bibr">[54,</ref><ref type="bibr">70]</ref>-in terms of F1 score, synthesis time, and robustness to data noise-and can flexibly synthesize complex queries that the baselines do not support. We also conduct a user study to show the performance of real users using EQUI-VOCAL.</p><p>Overall, EQUI-VOCAL is an important step toward making video database management systems more accessible to experts and nonexperts alike, by easing the task of expressing queries over videos.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2">EQUI-VOCAL DATA MODEL</head><p>This section describes EQUI-VOCAL's data model and query language, which we briefly introduced in our vision paper <ref type="bibr">[19]</ref>, but develop in depth here. Section 3 shows how EQUI-VOCAL synthesizes queries from user input using this data model.</p><p>For ease of presentation, we use a simplified, running example, where a traffic engineer seeks to find instances of "a car arriving from the left and passing a motorcycle at the intersection. " Figure <ref type="figure">2</ref> shows two representative frames from a video that contains such an event. We show other example queries in Section 5.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.1">Scene graphs as our data model</head><p>EQUI-VOCAL represents a video &#119881; as a set of short, nonoverlapping video segments, &#119907; &#8712; &#119881; (5-second segments in our prototype implementation). Each video segment is a sequence of &#119873; frames {&#119891; 1 , . . . , &#119891; &#119873; }. The visual content of each frame is represented by a scene graph <ref type="bibr">[43]</ref>: A scene graph &#119892; &#119894; = (o &#119894; , r &#119894; ) contains the set of all objects o &#119894; in a frame, along with a set of all relationships r &#119894; between those objects. Often a scene graph contains more information than is necessary to identify an event, and so the literature also defines a region graph &#119892; &#119894; &#119895; , which is a subgraph of &#119892; &#119894; , i.e., &#119892; &#119894; &#119895; &#8838; &#119892; &#119894; . Figure <ref type="figure">2</ref> (left) shows an example frame and region graph.</p><p>We define an object in a frame as &#119900; = (&#119907;&#119894;&#119889;, &#119891; &#119894; , &#119900;&#119894;&#119889;, &#119888;&#119894;&#119889;, &#119887;&#119887;&#119900;&#119909;), where &#119891; &#119894; is the sequence number of frame &#119894; in video segment, &#119907;&#119894;&#119889;. &#119900;&#119894;&#119889; is a unique identifier of the object in the video segment, &#119888;&#119894;&#119889; is the identifier for the class of the object (e.g., "car", "motorcycle"), and &#119887;&#119887;&#119900;&#119909; is the bounding box containing the object in frame, &#119891; &#119894; . A &#119887;&#119887;&#119900;&#119909; is represented by its upper-left and bottom-right coordinates, i.e., &#119887;&#119887;&#119900;&#119909; = (&#119909; 1 , &#119910; 1 , &#119909; 2 , &#119910; 2 ).</p><p>Objects can have intra-frame relationships defined as &#119903; = (&#119907;&#119894;&#119889;, &#119891; &#119894; , &#119903;&#119894;&#119889;, &#119900;&#119894;&#119889; sub , &#119901;&#119894;&#119889;, &#119900;&#119894;&#119889; tar ), where &#119903;&#119894;&#119889; is a unique identifier of the relationship in frame, &#119891; &#119894; . Subject, &#119900; sub , is connected to target, &#119900; tar , with the relationship class identifier, &#119901;&#119894;&#119889; (e.g., "near" or "holds"). Both subject and target belong to frame &#119891; &#119894; : i.e., &#119900; sub , &#119900; tar &#8712; o &#119894; .</p><p>Objects can have attributes &#119886; = (&#119907;&#119894;&#119889;, &#119891; &#119894; , &#119900;&#119894;&#119889;, &#119896;, &#119907;), where &#119896; is the name of the attribute, &#119907; is the value of the attribute, &#119907;&#119894;&#119889;, &#119891; &#119894; and &#119900;&#119894;&#119889; identify the video segment, frame, and object. EQUI-VOCAL distinguishes state and property attributes. The former change over time and are typically computed from the bounding box of an object (e.g., "location=bottom"). The latter capture intrinsic properties of objects and are immutable (e.g., "color=red").</p><p>Finally, an event &#119890; is a temporally ordered sequence of region graphs &#119890; = (&#119890;&#119894;&#119889;, {&#119892; 1 , . . . , &#119892; &#119896; }). Region graphs in an event do not need to be contiguous or distinct.</p><p>Example. Suppose that the two frames in Figure <ref type="figure">2</ref> are the 10th and 15th frames of a video segment V1, and that the motorcycle and car are the 7th and 9th objects detected in V1. Then, for the left frame, we generate the region graph &#119892; 1 = (o 1 , r 1 ), where: o 1 = {&#119900; 11 , &#119900; 12 } represents the car &#119900; 11 = (V1, F10, OID9, car, &#119887;&#119887;&#119900;&#119909; 1 ) and the motorcycle &#119900; 12 = (V1, F10, OID7, motorcycle, &#119887;&#119887;&#119900;&#119909; 2 ) and r 1 = {&#119903; 11 } contains a relationship &#119903; 11 = (V1, F10, RID1, OID9, leftOf, OID7). The car also has an attribute &#119886; 11 = (V1, F10, OID9, location, bottom). We can define the region graph &#119892; 2 for the right frame similarly. The only difference will be the relationship between the object will indicate that the car is now rightOf the motorcycle. Finally, the event &#119890; = (EID1, {&#119892; 1 , &#119892; 2 }) represents a car arriving from the left and passing a motorcycle at the intersection.</p><p>The relational schema in Table <ref type="table">1</ref> captures the above data model. The benefit of using a relational schema is that we can execute relational queries to specify region graphs and find events of interest, which is flexible and follows the well-understood semantics of the relational model. For each video (or collection of related videos), EQUI-VOCAL creates a view with this schema. In Section 4 we describe when and how relations in the view are materialized. To populate each relation, EQUI-VOCAL uses available userdefined functions (Figure <ref type="figure">1</ref>). User-defined functions can be provided by the user or be available publicly in the form of existing machine learning models, such as object detectors. Various user-defined functions can be declared in EQUI-VOCAL: (i) an object detector <ref type="bibr">[62]</ref> that takes a video frame as input and outputs the set of objects and their bounding boxes, (ii) an object tracking algorithm <ref type="bibr">[78]</ref> that takes objects in consecutive frames as input and, for each pair of objects, determines if they are the same, and (iii) a set of pretrained models (e.g., <ref type="bibr">[12]</ref>) or rules that can take two objects in the same frame as input and determine their relationship (e.g., "near", "behind", "riding", "holding") or that can take one object as input and determine its attributes (e.g., "location=bottom", "color=red").</p><p>In our experiments, EQUI-VOCAL uses a general-purpose object detector <ref type="bibr">[31]</ref> to locate objects and intrinsic attributes of objects to generate trajectories across frames <ref type="bibr">[81]</ref>.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.2">Scene graphs as our query language</head><p>EQUI-VOCAL could execute arbitrary relational queries on the view defined above. However, this would form an intractable search space, making query synthesis unusably slow for most real-world applications. Instead, we define a query language that is more restrictive, affording a smaller search space and therefore, faster synthesis. We constrain queries to (i) a temporally ordered sequence of region graphs, (ii) a set of predicates, (iii) a set of duration constraints, (iv) a window specification, and (v) to output video segment identifiers. Using Datalog and with some abuse of notation, a query in EQUI-VOCAL can be expressed as: &#119902;(&#119907;&#119894;&#119889;) :-&#119892; 1 , . . . , &#119892; &#119896; , p, d, &#119908;, where:</p><p>&#8226; A temporally ordered sequence of region graphs &#119892; 1 , . . . , &#119892; &#119896; specifies that a matching event consists of &#119892; 1 , followed by &#119892; 2 , followed by &#119892; 3 , etc. Each &#119892; &#119894; is specified with a set of atoms: Objects, Relationships, and Attributes joined on a shared &#119907;&#119894;&#119889; and &#119891; &#119894;&#119889;. Moreover, each &#119892; &#119894; can persist for multiple frames and there can be other frames between &#119892; &#119894; and &#119892; &#119894;+1 . &#8226; A set of predicates p can be applied to objects, relationships, and attributes. In our example, predicates would specify that the query is looking for "car" and "motorcycle" objects, that the car needs to be "left of" then "right of" the motorcycle, and that the car should be at the "bottom" of the frame. &#8226; A set of duration constraints d can be applied to region graphs and define the minimum number of contiguous frames that a region graph &#119892; &#119894; should be valid before transitioning to the next region graph &#119892; &#119894;+1 . &#8226; A window specification &#119908; is the maximum number of frames that can separate &#119892; 1 from &#119892; &#119896; .</p><p>For example, following the above restricted template, the event in Section 2.1 can be expressed with the following Datalog rules:<ref type="foot">foot_0</ref>  Caesar <ref type="bibr">[49]</ref> STAR <ref type="bibr">[14]</ref> VidCEP <ref type="bibr">[80]</ref> CVQL <ref type="bibr">[45]</ref> Quivr <ref type="bibr">[54]</ref> Rekall <ref type="bibr">[23]</ref> Ours</p><p>Query by example &#10003; &#10003; g1(vid, fid, oid1, oid2) :-Objects(vid, fid, oid1, 'car', _, _, _, _), Objects(vid, fid, oid2, 'motorcycle', _, _, _, _), Relationships(vid, fid, _, oid1, 'leftOf', oid2), Attributes(vid, fid, oid1, 'location', 'bottom'), oid1 != oid2.</p><p>The above rule will find frames in video segments that contain a car and a motorcycle, such that the car is on the left of the motorcycle, and the car is at the bottom of the frame, where the intersection is located. Next, the event will likely consist of a sequence of such frames, which can be captured with the following recursive rules: g1_star(vid, fid, fid, oid1, oid2) :-g1(vid, fid, oid1, oid2). g1_star(vid, fid_start, fid_end, oid1, oid2) :-g1_star(vid, fid_start, fid, oid1, oid2), g1(vid, fid_end, oid1, oid2), fid_end = fid + 1.</p><p>We could use equivalent rules to define g2 and g2_star. Finally, the query that returns matching video segments takes the form: q(vid) :-g1_star(vid, fid11, fid12, oid1, oid2), g2_star(vid, fid21, fid22, oid1, oid2), fid21 &gt; fid12, fid22 -fid11 &lt; 1800</p><p>The predicate &#119891; &#119894;&#119889;21 &gt; &#119891; &#119894;&#119889;12 indicates that the second sequence of region graphs should follow the first one. The predicate allows for a gap between sequences, which may arise, for example, if something obstructs the vehicles from the camera's view. Finally, &#119891; &#119894;&#119889;22 -&#119891; &#119894;&#119889;11 &lt; 1800 puts a time constraint on the event (a 30second time-window, assuming 60 frames per second).</p><p>To summarize, EQUI-VOCAL's query language is a subset of Datalog with recursion, expressed on a specific schema. In Section 4, we explain how we avoid executing expensive recursive queries.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.3">Expressiveness of our data model</head><p>We compare the expressiveness of EQUI-VOCAL's data model against other compositional video analytics systems in Table <ref type="table">2</ref>. Among them, SVQ++ <ref type="bibr">[11]</ref> only supports spatial relationships between two objects, Chen et al. <ref type="bibr">[16]</ref> only supports temporal queries that count co-occurring objects. Caesar <ref type="bibr">[49]</ref>, STAR Retrieval <ref type="bibr">[14]</ref>, and VidCEP <ref type="bibr">[80]</ref> lack the important feature of iteration that allows a region graph to persist for multiple frames and thus cannot support duration constraints. CVQL <ref type="bibr">[45]</ref> does not track objects and all its predicates are defined at the object class level. Quivr <ref type="bibr">[54]</ref> has similar expressiveness to us, but is limited to trajectory queries. Rekall <ref type="bibr">[23]</ref> introduces a flexible Python library for video event specification, but requires that users manually write and refine queries.</p><p>Our data model currently does not support tertiary relationships between three objects, such as "a person hitting a ball with a bat". The closest approximation we have is "a person holding a bat" and "a bat hitting a ball". We also do not support disjunctions or negations. Several existing systems have support for these operators.</p><p>For example, Chen et al. <ref type="bibr">[16]</ref> supports arbitrary CNF queries, Caesar <ref type="bibr">[49]</ref> supports disjunctions, and Rekall <ref type="bibr">[23]</ref> can flexibly support all three operators. However, the focus of these systems lies in query execution, rather than in learning query specifications from examples, which is the primary focus of this paper.</p><p>Datalog and scene graphs serve as the foundation of our query language. By building on the relational model and Datalog, we ensure that our queries have precise and well-understood semantics. By focusing on queries that specify a desired sequence of region graphs, we constrain the search space for queries, which accelerates synthesis, we are able to optimize the execution of those queries (compared with trying to support arbitrary recursive Datalog queries), and we are still able to capture events that occur in videos, where objects interact with each other in space and time.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3">QUERY SYNTHESIS</head><p>With our data model and query language defined, we now formally present the query synthesis problem statement, then describe all the components of our proposed solution.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.1">Query synthesis problem statement</head><p>Following the aforementioned data model, a user would like to execute a query &#119902; &#119906; on video database &#119863; that returns a set of video segment identifiers, &#119881; &#119900;&#119906;&#119905;&#119901;&#119906;&#119905; = &#119902; &#119906; (&#119863;). Given the user's intended query, &#119902; &#119906; , each video segment &#119907; &#119894; can be seen as having a groundtruth label &#119910; &#119894; &#8712; {0, 1} indicating whether it matches &#119902; &#119906; . Initially, both the ground-truth labels and &#119902; &#119906; are unknown because the user is unable to specify &#119902; &#119906; and can only label video segments as positive or negative instances. The goal of EQUI-VOCAL is to synthesize a target query, &#119902; &#119905; &#8712; &#119876;, that is the best approximation of &#119902; &#119906; in its search space. When executed over database &#119863;, &#119902; &#119905; should yield the best measure performance (e.g., F1 score):</p><p>EQUI-VOCAL can request a label from the user &#119874;: &#119910; &#119894; &#710;= &#119874; (&#119907; &#119894; ). Since user labels may be noisy, it is possible that &#119910; &#119894; &#710;&#8800; &#119910; &#119894; . Given that enumerative search is intractable, EQUI-VOCAL uses a heuristic approach to find an approximately-best query &#119902; &#710;&#119905; to the objective, while reducing both user effort and query synthesis time.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.2">Query synthesis algorithm overview</head><p>Algorithm 1 provides an overview of EQUI-VOCAL's synthesis algorithm. It traverses the space of possible queries to synthesize a final target query that matches the user's intent. The algorithm takes as input the set of unlabeled video segments, &#119880; , and a small set of labeled segments, &#119871;. &#119871; is provided by the user and should include both positive and negative examples of the desired event.</p><p>In our experiments, we require as few as two positive and ten negative examples. While providing these examples requires extra work from the user, such a setting is common in query-by-example approaches <ref type="bibr">[22,</ref><ref type="bibr">54,</ref><ref type="bibr">61]</ref>. We leave starting with zero examples for future work. The algorithm also takes as input a set of user-defined functions, &#119875;, comprised of indicator functions for object classes (e.g., "car"), relationships (e.g., "near"), and attribute key-value pairs  Algorithm 1: Query synthesis algorithm that returns top-&#119896; synthesized queries matching user input.</p><p>Input :&#119880; -set of unlabeled video segments &#119871; -set of labeled video segments &#119875; -set of user-defined functions &#119887;, &#119887;&#119908;, &#119904; &#119902; , &#119904; &#119907; , &#119896; -hyperparameters Output :&#119876; &#119905; -set of top-&#119896; target queries</p><p>11 return &#119876; &#119905; (e.g., "color=red"). Algorithm 1 enumerates &#119875; when expanding its search space.</p><p>The algorithm returns a set of target queries, &#119876; &#119905; , which is the top-&#119896; synthesized queries ranked by a performance measure (F1 score in our prototype implementation) and is updated regularly through the search process. The learned queries can be applied to unseen videos to find video segments containing the matching event. By default, EQUI-VOCAL returns the top-&#119896; queries but then executes the best one over unseen videos. The user can also randomly sample one query from &#119876; &#119905; , execute multiple queries from &#119876; &#119905; and aggregate the results, or manually examine &#119876; &#119905; to pick the intended query. If the user is not satisfied with the synthesized query, they can edit it directly. The user can also restart the search with a larger number of initial examples by reusing the video segments labeled during the last session. Moreover, the user could provide a starter query to EQUI-VOCAL (e.g., a simple query or an earlier query) rather than starting from an empty query.</p><p>To populate &#119876; &#119905; efficiently, EQUI-VOCAL synthesizes queries in a bottom-up fashion. It starts with an empty query, &#119902; &#8709; , and incrementally adds predicates to it, up to a certain complexity (ExpandQuery method on line 5 and Section 3.3). At each step, different predicates can be added to a query, expanding the search in multiple directions. To limit the size of the search space and ensure fast query synthesis, EQUI-VOCAL adopts a beam searchstyle strategy (SampleQueries method on line 8 and Section 3.4).</p><p>An important challenge for EQUI-VOCAL is that learning a query from a small number of user-provided examples is difficult.</p><p>To address this challenge, EQUI-VOCAL uses active learning to effectively guide the query synthesis process and identify good target queries with limited initial and additional user effort. Specifically, method PickNextSegments on line 7 and in Section 3.5 uses active learning to select additional video segments for the user to label in order to effectively differentiate between multiple candidate subqueries, and expand the search in the most promising directions.</p><p>At the end of each iteration, method RetainTopQueries (line 10 and Section 3.6) maintains a list of top-&#119896; queries seen so far, which is larger than the number of queries selected for additional expansion, in case a query seen earlier in the search ends up with the best score on the final labeled set of segments, or, as mentioned above, to give users options if they would like to try alternative, high-performing queries.</p><p>The algorithm has several hyperparameters, including a labeling budget &#119887; (i.e., the maximum number of labels the user is willing to provide), the number of candidate queries to retain during exploration &#119887;&#119908; (i.e., the beam width), the number of candidate queries, &#119904; &#119902; , and the number of candidate video segments, &#119904; &#119907; , sampled during active learning, and the number of queries in the final answer &#119896;. Figure <ref type="figure">3</ref> illustrates the algorithm using the running example.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.3">Query expansion</head><p>Existing query-by-example systems use sketch-based query synthesis approaches <ref type="bibr">[54,</ref><ref type="bibr">70,</ref><ref type="bibr">73]</ref> to enumerate candidate queries. A sketch query is a query with unspecified parts in the form of holes and these approaches enumerate the search space by first generating high-level sketch queries and then filling them with low-level details. However, enumerative search is slow and memory-intensive. Inspired by execution-guided synthesis approaches <ref type="bibr">[13,</ref><ref type="bibr">34]</ref>, which treat a program as a sequence of manipulations and use the results of partial programs to guide the search, EQUI-VOCAL explores the search space based on the results of executing intermediate queries on the examples. Instead of synthesizing sketch queries with uninstantiated holes that cannot be executed directly, or directly applying techniques from <ref type="bibr">[13,</ref><ref type="bibr">34]</ref>, which require a large amount of data to train a neural synthesizer, EQUI-VOCAL expands queries by adding instantiated and executable constraints, executing partial queries to assess the promise of each explored path, and iteratively refining a query towards the target query.</p><p>In our synthesis algorithm, method ExpandQuery(&#119902;, &#119875;) takes as input a query &#119902; to expand, and a set of user-defined functions, &#119875; to construct more complex queries. The function returns a set of expanded queries as illustrated in Figure <ref type="figure">3(a)</ref>.</p><p>Our query synthesis approach uses a compact query notation, which can be seen as a DSL. The DSL captures the logical structure of the queries to synthesize and key query parameters, but omits the details of the full, underlying SQL (or Datalog). This approach is important for several reasons: First, since we do not generate arbitrary SQL, but rather queries that conform to the structure presented in Section 2.2, the DSL captures that structure precisely, simplifying the search space and guiding synthesis toward the correctly-structured queries. Second, this approach helps to decouple the logical query specification from the details of the SQL queries that are ultimately executed. As we present in Section 4, critical optimizations are necesssary during the translation from our DSL to SQL to achieve efficient query execution.</p><p>In our DSL, we use a variable &#119900; to represent an object in a query. Different variables represent objects with different &#119900;&#119894;&#119889;'s. All predicates of a region graph are connected by commas and are represented with shorthand notations that specify only their key-value pairs (for property attributes, e.g., Color(&#119900; 1 , 'cyan')), value (for state attributes, e.g., Bottom(&#119900; 1 )), or class (for objects and relationships, e.g., Car(&#119900; 1 )). Then, region graphs are connected in sequence with semicolons. For example, the query for the event from Section 2.1 can be represented as:</p><p>We further use the notation Duration(&#119892;, &#119889;) to require that the region graph &#119892; exist in at least &#119889; consecutive frames. During query synthesis, EQUI-VOCAL expands queries written in our DSL. ExpandQuery takes any of the following three actions: As shown in Figure <ref type="figure">3</ref>(a), EQUI-VOCAL starts with an empty query &#119902; 0 = &#119902; &#8709; . In iteration 1, EQUI-VOCAL takes action SC to expand &#119902; 0 . This results in &#119902; 1 to &#119902; 5 , each consisting of a single region graph with one predicate drawn from &#119875;. In iteration 2 of Figure <ref type="figure">3</ref>(a), EQUI-VOCAL first expands &#119902; 1 = LeftOf(&#119900; 1 , &#119900; 2 ). Performing action GC leads to &#119902; 6 = (LeftOf(&#119900; 1 , &#119900; 2 ), Bottom(&#119900; 1 )); SC leads to &#119902; 7 = LeftOf(&#119900; 1 , &#119900; 2 ); Bottom(&#119900; 1 ); and DR leads to &#119902; 8 = Duration(LeftOf(&#119900; 1 , &#119900; 2 ), 5), assuming the granularity of Duration is 5 frames.</p><p>Deciding which actions to take to expand queries is an important design decision. We consider both a restrictive rule that constrains each query to have one construction path and a relaxed rule that allows each query to be generated through all possible permutations of actions with multiple construction paths. Our early experiments showed that the relaxed rule led to better performance. It is thus the approach that we use. Specifically, GC can add any predicates that are not already in the region graph (predicates from the same userdefined function but applied to different variables are considered as different); SC can insert a new region graph before or after any existing region graph; DR can increment the duration constraint of any existing region graph (more details in our technical report <ref type="bibr">[84]</ref>).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.4">Beam search</head><p>When traversing the search space, we can greedily expand only the top query or exhaustively expand all. The former is quick to compute but may not find the target query, while the latter is optimal but comes with a prohibitive computational cost. EQUI-VOCAL uses beam search to balance query performance and synthesis efficiency. Beam search has a wide range of applications in problems with large search spaces <ref type="bibr">[44,</ref><ref type="bibr">50,</ref><ref type="bibr">72]</ref>. The greedy approach can be viewed as a special case of the beam search with a beam width of one, and the exhaustive search is equivalent to having an infinitely large beam width. Beam search reduces runtime by limiting the number of explored branches at each iteration. However, the search outputs are not guaranteed to be optimal. Search quality depends on how branches are expanded, scored, and pruned. In our approach, method SampleQueries(&#119878; &#8242; , &#119871;, &#119887;&#119908;) retains the top &#119887;&#119908; queries to expand by evaluating the F1 score of the &#119878; &#8242; candidate queries on the set of labeled video segments &#119871; (see Figure <ref type="figure">3(c)</ref>). Prior work has analyzed the theoretical properties of beam search under certain assumptions (e.g., monotonicity of scoring functions <ref type="bibr">[53]</ref>, Bayes optimality of tree models under approximations <ref type="bibr">[85]</ref>). While in this paper, we directly use the F1 score as the scoring function and to retain top queries, other more sophisticated scoring functions and pruning techniques can be used as alternatives <ref type="bibr">[1,</ref><ref type="bibr">53,</ref><ref type="bibr">72]</ref>. We show the effectiveness of our synthesis algorithm empirically in Section 5.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.5">Active learning</head><p>One challenge with asking the user for only a handful of examples of the intended event is that we risk overfitting, but asking the user to find a larger number of initial examples is difficult. To address this challenge, we use active learning during query synthesis.</p><p>Many active learning methods have been proposed in the literature with the goal of labeling samples that maximally improve a model trained on those samples, e.g., uncertainty-based sampling <ref type="bibr">[47]</ref>, estimated error reduction <ref type="bibr">[64]</ref>, and core-set approach <ref type="bibr">[66]</ref>. In our work, we use active learning to label samples that help us identify which candidate queries are better than others. To do so, we need to label samples where candidates disagree: Therefore, we use disagreement-based active learning <ref type="bibr">[42]</ref>. At every iteration, EQUI-VOCAL asks the user for a handful of additional labels to differentiate between the &#119887;&#119908; queries retained from the previous iteration. Intuitively, this method picks the video segments where the retained queries disagree the most. A similar idea appears in the query-by-committee algorithm <ref type="bibr">[68]</ref> and has been used in other program synthesis systems <ref type="bibr">[36,</ref><ref type="bibr">54]</ref>. EQUI-VOCAL's contribution is to incorporate active learning in each iteration of the search process, ensuring an interaction-level labeling experience. Using active learning reduces the number of data points a user has to provide; additionally, we posit that it is easier for users to label system-selected examples than to come up with their own.</p><p>During each call to PickNextSegments(&#119871;, &#119880; , &#119878; &#8242; ), EQUI-VOCAL computes a score for a sample of unlabeled video segments &#119880; over the candidate queries &#119878; &#8242; and then picks the video segments with the largest disagreement. The score of each sampled, unlabeled video segment is computed as the weighted disagreement between the candidate queries. The weight of each candidate query is set to its regularized performance over the labeled set &#119871; (Section 3.7).</p><p>While the algorithm in <ref type="bibr">[42]</ref> is designed for the setting where labeling candidates are streamed, EQUI-VOCAL instead maintains a pool of candidates. Therefore, for each call to PickNextSegments, EQUI-VOCAL computes the score for a sample of unlabeled video segments &#119904; &#119907; over a sample of candidate queries &#119904; &#119902; and then picks the best one. The function updates &#119871; and &#119880; given the new user labels. As shown in Figure <ref type="figure">3</ref>(a), EQUI-VOCAL generates five candidate queries &#119902; 1 to &#119902; 5 in iteration 1. Among them, &#119902; 1 has the highest score 0.6, while &#119902; 2 and &#119902; 3 give the same second highest score 0.4. EQUI-VOCAL requests a new video segment to be labeled (Figure <ref type="figure">3(b)</ref>), which distinguishes &#119902; 3 from &#119902; 2 (Figure <ref type="figure">3(c)</ref>).</p><p>Before query synthesis begins, users can set the labeling budget as a hyperparameter. EQUI-VOCAL precomputes the number of iterations of query expansion it will perform and uniformly divides the labeling budget among iterations. At every iteration, EQUI-VOCAL asks for new labels only if it has a labeling budget left to do so; otherwise, it proceeds to synthesize queries without requesting new labels. EQUI-VOCAL precomputes the number of iterations by relying on the hyperparameters (Section 4) that bound the search process and the query expansion rules (Section 3.3), which increments the complexity of synthesized queries in each iteration.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.6">Retaining top queries</head><p>At the end of each iteration, EQUI-VOCAL updates its list of candidate final queries in order to retain &#119896; best performing ones, as measured by their F1 scores on the labeled dataset. RetainTopQueries(&#119876; &#119905; , &#119871;, &#119896;) evaluates all candidate queries &#119876; &#119905; on labeled set &#119871; and returns the top &#119896;. In Figure <ref type="figure">3(d)</ref>, at the end of iteration 1, EQUI-VOCAL stores &#119902; 1 in &#119876; &#119905; because &#119896;=1, and &#119902; 1 has the highest score. When the algorithm terminates, EQUI-VOCAL returns &#119902; &#119894; as the final query. In our evaluation, we set the default value of &#119896; to 100 (and to 1000 for a more complex dataset), which ensures both low overhead and high-performing final queries.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.7">Regularization</head><p>EQUI-VOCAL retains top queries using their F1 scores on the smaller &#119871; labeled set. This can lead to overfitting since there are likely too few training examples to accurately evaluate each candidate query. To prevent overfitting, we regularize the score of each candidate query by adding the term: &#119904;&#119888;&#119900;&#119903;&#119890; reg (&#119902;) = &#119904;&#119888;&#119900;&#119903;&#119890; (&#119902;)-&#120582;&#8226;&#119877;(&#119902;), where &#120582; controls the importance of the regularization term. &#119877;(&#119902;) represents the complexity of the query &#119902;: &#119877;</p><p>. Here, &#119896; is the number of region graphs in &#119902;, &#119899; &#119901;&#119894; is the number of predicates in the &#119894;th region graph &#119892; &#119894; , and &#119899; &#119889;&#119894; denotes the scale of the duration constraint of &#119892; &#119894; . &#120572; 1 , &#120572; 2 , and &#120572; 3 are hyperparameters that control the importance of each term.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4">QUERY EXECUTION</head><p>As discussed in Section 3.3, we convert queries in our DSL into SQL and use a relational engine (PostgreSQL in our prototype) to execute them. In this section, we discuss important optimizations that we apply during this translation process. Query translation algorithm. In Section 2.2, we show that queries over videos are naturally recursive. Such queries, however, are slow to execute. To avoid recursion, we leverage the observation that those queries express the idea of iteratively matching a region graph in a contiguous sequence of frames, rather than arbitrary recursion. Therefore, we can express them using window functions instead of recursion. As a second optimization, we note that a query &#119902; in our DSL (Section 3.3) takes as input a set of video segments &#119881; and returns all segments in &#119881; containing at least one event that matches &#119902;. Therefore, instead of finding all satisfying events for each video segment, the query execution needs to find only one. We leverage this observation to reduce intermediate result sizes by producing SQL that efficiently computes the earliest matching sequences for each region graph specification. This optimization applies to queries without window specifications and whose duration constraints are of the form "&gt;" or "&gt;=", which are the only types of queries that EQUI-VOCAL currently generates. Caching. We implement an application-level cache to reuse subquery results. EQUI-VOCAL generates SQL queries as described above to find matching region graphs in the sequence specified by the DSL query one by one. We cache the intermediate results of all prefixes on the set of video segments to allow other queries sharing the same sub-queries to reuse the results. For example, when executing the query &#119902; = &#119892; 1 ; &#119892; 2 ; &#119892; 3 on video segments &#119907; 1 and &#119907; 2 , we cache the results of &#119902; 1 = &#119892; 1 , &#119902; 2 = &#119892; 1 ; &#119892; 2 , and &#119902; 3 = &#119892; 1 ; &#119892; 2 ; &#119892; 3 on &#119907; 1 and &#119907; 2 . Later, if a query &#119902; &#8242; = &#119892; 1 ; &#119892; 2 ; &#119892; 4 is executed on &#119907; 1 and &#119907; 3 , EQUI-VOCAL will reuse the cached results of &#119902; 2 = &#119892; 1 ; &#119892; 2 on &#119907; 1 . Bounding the search space. EQUI-VOCAL synthesizes queries up to a certain maximum size to ensure that the synthesis algorithm eventually terminates. Assume the number of user-defined functions for object classes and attributes is &#119898; 1 and the number of user-defined functions for relationships is &#119898; 2 . We bound the query search space using a set of hyperparameters: the maximum number of region graphs (&#119899; &#119892; ) in a query, the maximum number of predicates (&#119899; &#119901; ) in the query, the number of possible values a duration constraint can take (&#119899; &#119889; ), and the number of unique objects allowed in a query (&#119899; &#119907; ). The size of the search space is then</p><p>). Predicate evaluation. The current implementation of EQUI-VOCAL populates the Objects relation and the property attributes in the Attributes relation before query synthesis (see Table <ref type="table">1</ref>), by executing ML models on all video frames. The Relationships relation and the state attributes in the Attributes relation are computed lazily during query execution since they do not require ML models in our prototype, and are thus inexpensive to compute. In general, optimizing what information is computed before query synthesis and what is computed lazily is not the focus of this paper.</p><p>To simplify SQL query generation, we implement all predicates (except for join predicates) in EQUI-VOCAL as user-defined functions that take attributes and bounding box coordinates as input and return boolean values. In our prototype, we use PostgreSQL and implement user-defined functions for state and relationship predicates that operate on bounding boxes, and for property predicates that operate on key-value pairs.</p><p>While EQUI-VOCAL provides the above user-defined functions, the user can also provide additional user-defined functions incrementally as they use the system, and they can be shared and reused across queries and users <ref type="bibr">[76]</ref>. In practice, EQUI-VOCAL has to limit the number of user-defined functions to a reasonable amount to ensure the efficiency of query synthesis. Two objects are far apart for at least 5 frames, then they move close, then they are far again. 5.6% TQ2D Duration(LeftOf(&#119900; 1 , &#119900; 2 ), 5); (Near(&#119900; 1 , &#119900; 2 ), Top(&#119900; 1 ));</p><p>Duration(RightOf(&#119900; 1 , &#119900; 2 ), 5)</p><p>&#119900; 1 is on the left of &#119900; 2 for at least 5 frames, then they move close to each other and &#119900; 1 is at the top, then &#119900; 1 is on the right of &#119900; 2 for at least 5 frames.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>6%</head><p>TQ3D Duration( (Frontof(&#119900; 1 , &#119900; 2 ), Left(&#119900; 1 )), 15);</p><p>&#119900; 1 is in front of &#119900; 2 while &#119900; 1 is on the left for at least 15 frames, then &#119900; 1 moves to the right of &#119900; 2 while &#119900; 1 is at the top left for at least 5 frames. </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>8.3%</head></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5">EVALUATION</head><p>We conduct an experimental evaluation of EQUI-VOCAL. First, we show that on both synthetic and real-world datasets, compared to existing systems, EQUI-VOCAL reduces the query synthesis time by 1-2 orders of magnitude, achieves comparable or better F1 scores under the same labeling budget, is more robust to noisy data, and explores and executes queries more efficiently. Second, we show that EQUI-VOCAL is capable of synthesizing more complex, flexible queries over arbitrary scene graphs, which existing systems cannot handle. Third, We conduct a user study to demonstrate the effectiveness and usability of EQUI-VOCAL. We further compare EQUI-VOCAL with a machine learning method and conduct an ablation study by varying the various design choices outlined earlier.</p><p>We defer the details of the ablation study to the technical report <ref type="bibr">[84]</ref>. Baselines. To the best of our knowledge, there are no existing systems that can synthesize queries over scene graphs. The most similar system to EQUI-VOCAL is Quivr <ref type="bibr">[54]</ref>, which synthesizes queries over trajectories. Since object trajectories can be represented using scene graphs, we compare our system against Quivr. We also compare against PATSQL <ref type="bibr">[70]</ref>, which is a state-of-the-art query-by-example system for relational data. Predicates. For the synthetic dataset, we use 13 predicates in experiments: six relationship predicates (Near, Far, LeftOf, RightOf, FrontOf, and Behind), four state predicates (Left, Right, Top, Bottom), and three property predicates (Color, Material, and Shape). We consider eight colors, two materials, and three shapes. Property predicates are only used for the scene graphs dataset. For duration constraints, we consider three possible values: duration(&#119892;) &#8805; 5, 10, or 15 frames. Section 4 discussed how EQUI-VOCAL evaluates these predicates. For the real dataset, we use nine predicates: two relationship predicates (Faster, Near) and seven state predicates (LaneK, Stopped, HighAccel). LaneK detects whether a car is in lane K, and we identify five lanes in the video. Data. We evaluate our system on both synthetic and real-world datasets. We first evaluate on the CLEVRER dataset <ref type="bibr">[81]</ref>, which comprises synthetic videos of moving objects. This dataset includes a variety of geometric shapes interacting in space and time, and comes with ground truth data, facilitating testing queries with varying complexities. We create two benchmarks from this data: trajectories and scene graphs datasets. Trajectories dataset. We create a first dataset to test queries over trajectories, which baseline systems support. We extract 10,080 pairs of object trajectories that overlap in time from 500, 5-second video segments. Each trajectory pair is essentially a temporally ordered sequence of bounding box pairs &#119887; = (&#119909; &#119886;1 , &#119910; &#119886;1 , &#119909; &#119886;2 , &#119910; &#119886;2 , &#119909; &#119887;1 , &#119910; &#119887;1 , &#119909; &#119887;2 , &#119910; &#119887;2 ) representing two objects in a video segment. We manually generate a set of queries with varying complexities (Table <ref type="table">3</ref>). To generate ground truth labels, we run each target query on the dataset. We sample 500 trajectory pairs as training data (i.e., data used during query synthesis) and use the rest as test data (i.e., to measure the quality of synthesized queries). Scene graphs dataset. This more complex dataset contains scene graphs extracted from the CLEVRER dataset, which baseline systems do not support. We extract scene graphs from 10,000, 5-second video segments. For every frame of a video segment, we store the object track ID (&#119900;&#119894;&#119889;), bounding box coordinates, and object attributes (shape, color, and material) of every object in the frame (the Objects and Attributes relations in Table <ref type="table">1</ref>). We sample 500 video segments as training data and use the rest as test data. We automatically generate three classes of queries with different complexities: easy, medium, and hard. Each generated query contains exactly three variables (i.e., three distinct objects). Easy queries have exactly three predicates on relationships and states, one property predicate, one region graph, and no duration constraints; medium queries have exactly five predicates on relationships and states, two property predicates, three region graphs, and no duration constraints; hard queries have the same complexity as medium queries but also include duration constraints with three possible values. Each class contains 40 queries. Real-world dataset. We test on a 50-minute traffic video from the YTStreams dataset <ref type="bibr">[5]</ref>. The dataset comes with car trajectories, Table <ref type="table">5</ref>: Query synthesis time (median, in seconds) for each method to achieve at least 0.9 F1 scores. EQUI-VOCAL successfully learns all queries with at least 0.9 F1 scores and is faster than (or at least comparable to) the two baselines. (NA: not applicable, -: failed due to insufficient F1 score or timeout)</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Method</head></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Simplified</head><p>Normal TQ1 TQ2 TQ3 TQ4 TQ5 TQ6 TQ7 TQ8 TQ9 TQ1 TQ2 TQ3 TQ4 TQ5 TQ6 TQ7 TQ8 TQ9 TQ1D TQ2D TQ3D PATSQL 1.</p><p>54 -538 -4.00 1.93 552 --NA NA NA NA NA NA NA NA NA NA NA NA Quivr 10.5 5.77 27.9 94.2 13.5 4.36 47.7 16.7 -7228 7428 8185 -7839 3683 -8756 ----Ours 3.57 1.85 17.1 46.6 4.36 1.66 18.5 22.7 20.6 75.6 125 106 185 50.4 61.1 106 110 107 223 166 183</p><p>and we further extract the velocity and acceleration of each car trajectory as the object attributes, following the same procedure described in <ref type="bibr">[54]</ref>. From the video, We create 72,159 pairs of overlapping car trajectories, using half of them as training data and the rest as test data. For our evaluation, We adopt 13 queries from <ref type="bibr">[54]</ref>, with some adjustments, including the use of a different in-lane detection method, removal of real-valued parameters from predicates, and expression of queries using scene graphs, and the introduction of additional queries with two scene graphs. These queries capture a wide range of car behaviors (Table <ref type="table">4</ref>).</p><p>Metrics. We report the F1 score and query synthesis time. We synthesize queries using the training set and report the F1 score of the query (or the median F1 score if there are multiple queries with the same best score on the training set) over the test set. Each experiment is run 20 times for the trajectories and real-world datasets and five times for the scene graphs dataset, and we report the median F1 score and query synthesis time over these runs. Implementation details. We implement our prototype in Python with PostgreSQL as the backend. We conduct all experiments except for the user study on a computing cluster with Intel Xeon Gold 6230R CPUs at 2.10GHz. When measuring runtimes, we request one node with one core and 100GB of RAM. Unless otherwise specified, we configure EQUI-VOCAL as follows. For the trajectories dataset and the real-world dataset, we search for queries with up to 5 predicates across up to 3 region graphs. We use beam width &#119887;&#119908; = 10, &#120582; = 0.01 for regularization (with &#120572; 1 = &#120572; 2 = 1, and &#120572; 3 = 0.1, see Section 3.7), and we set &#119896; = 100, &#119904; &#119902; =100, and &#119904; &#119907; = 100. For the scene graphs dataset, we search for queries with up to 7 predicates, 3 region graphs, and 3 objects. Since the dataset is more complex and challenging, we use a smaller &#120582; (because the query complexity term, &#119877;(&#119902;) has a greater absolute value) and a greater &#119896;. We use beam width &#119887;&#119908; = 10, &#120582; = 0.001 for regularization (with &#120572; 1 = &#120572; 2 = 1, and &#120572; 3 = 0.1), and we set &#119896; = 1000, &#119904; &#119902; =100, and &#119904; &#119907; = 100. The user study is conducted on an AWS EC2 c6id.4xlarge instance with 16 vCPUs and 32GB of RAM. We search for queries with up to 7 predicates, 3 region graphs, and 3 objects. For duration constraints, we consider three possible values, 25, 50, and 75 frames, which translate to 1, 2, and 3 seconds. To improve the interactivity of the system, we use a smaller beam width &#119887;&#119908; = 5 and a smaller sample of candidate queries &#119904; &#119902; = 25 for active learning. We set &#119904; &#119907; = 100, &#120582; = 0.001 and &#119896; = 100.</p><p>We consider two variants of Quivr. As per the original paper, we limit the number of atomic predicates in Quivr's queries to 5 and the depth of the nested constructs to 3, which leads to a similar search space as EQUI-VOCAL. When considering queries without duration constraints (e.g., TQ1-TQ9), we omit Kleene star operators from its search space. Otherwise (e.g., TQ1D-TQ3D), we include Kleene star in the query expansion and add one more predicate MinLength &#120579; , which checks whether the duration of the input is at least &#120579; frames. Quivr returns all queries that match the examples, so we select the queries with the simplest structure (which is determined by the number of atomic predicates, and, if the former is the same, by the depth) and report their median F1 score.</p><p>Because PATSQL requires that all user-provided input tables be used in the solution query, when comparing against PATSQL, we restrict all systems to only the candidate predicates that appear in the target query. Because PATSQL cannot handle large tables efficiently, we also downsample each trajectory by 75% (we keep one frame out of four) to reduce the size of the input tables. We refer to this configuration as simplified tasks.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.1">Results against baselines on trajectories</head><p>We evaluate EQUI-VOCAL against the two baselines on the trajectories dataset and the set of queries in Table <ref type="table">3</ref>. We run each method as follows. For each target query, we randomly select 2 positive and 10 negative examples from the training set and use them as the input to the method. Each method then asks for &#119887; additional examples during the search. For PATSQL, since it is not interactive, we simply sample &#119887; more examples randomly from the remaining dataset and provide the 12 + &#119887; examples to the system at the beginning. For Quivr and EQUI-VOCAL, we input the 12 initial examples, and each system actively requests more examples during the search process.</p><p>EQUI-VOCAL is faster than baselines and can find highperformant queries even for complex queries. Table <ref type="table">5</ref> shows the query synthesis time of each query to achieve at least a 0.9 F1 score. For simplified tasks, EQUI-VOCAL outperforms baselines on 6 queries. PATSQL performs the best or close to the best when queries are simple (TQ1, 5, and 6) because these queries include only two predicates and PATSQL terminates once it finds one solution query. Quivr is slower than EQUI-VOCAL but comparable to it except for TQ9, in which case Quivr fails due to an insufficient F1 score of the synthesized queries. Under the normal setting, EQUI-VOCAL is significantly more efficient than Quivr and can find high-performance queries in hundreds of seconds even for complex queries with duration constraints, while Quivr cannot synthesize TQ4, TQ7, TQ9, and TQ1D-TQ3D within 4 hours due to the large number of queries that need to be explored in the enumerative search. EQUI-VOCAL achieves a faster synthesis time than Quivr by exploring fewer queries using beam search and by executing every query faster. For example, for TQ3 under the normal setting, Quivr explores 221K queries while EQUI-VOCAL only explores 1101 queries, and EQUI-VOCAL executes each query 4.7&#215; faster. We include the detailed performance results in our technical report <ref type="bibr">[84]</ref>.</p><p>On simplified tasks, EQUI-VOCAL and QUIVR find queries with similar F1 scores and outperform PATSQL for   the same labeling budget. Figure <ref type="figure">4</ref> shows the F1 score of each system when varying the user labeling budget on the simplified tasks (which all systems can perform). We assign an F1 score of 0 if a system fails to find a query in 1 hour. Across all labeling budgets tested, as above, PATSQL performs well when the target query is simplest (TQ1, 5, and 6). For other queries, PATSQL either fails to find a solution query within 1 hour or the solution query has low performance (below a 0.9 F1 score). When the budget is 30, we observe a decrease in F1 scores for TQ3, 7, 8, and 9, because PATSQL has a less constrained search space than EQUI-VOCAL and does not scale well when the size of input and output tables increases as more examples are provided. Quivr performs better than EQUI-VOCAL when no additional examples are requested (budget=12) because it enumerates the entire search space and finds all consistent queries using the initial examples, while EQUI-VOCAL prunes candidate queries at every iteration to ensure efficient query synthesis. With a larger labeling budget, EQUI-VOCAL can request more labels during the search process to select better paths to explore, thus it catches up with Quivr and outperforms it when the budget is 30. EQUI-VOCAL is more robust to noisy data and produces higher quality queries than Quivr. We compare the performance of Quivr and EQUI-VOCAL when the data is noisy. We do not compare against PATSQL since its performance on video queries is already low even with perfect data. We inject noise into the original dataset by randomly flipping a fraction of the labels. We vary the false negative rate from 0.1 to 0.5 and set the false positive rate to 0.1 the false negative one. Table <ref type="table">6</ref> shows the percentage of runs when the system returned any queries for different : EQUI-VOCAL can synthesize high-quality queries within a reasonable budget, even for scene graph queries. noise rates. We evaluate the systems over 9 queries (TQ1-TQ9) in the simplified setting. For Quivr, we also report the range of the success rate besides the mean value. When the false negative rate is 0.1, Quivr has a 68% success rate, and this goes down to only 17% when the false negative rate is 0.5. In contrast, EQUI-VOCAL always returns &#119896; queries. To demonstrate that EQUI-VOCAL also produces higher quality queries, Figure <ref type="figure">5</ref> shows the F1 score of EQUI-VOCAL and Quivr with a labeling budget of 20, under two different noise rates. When Quivr fails to return any queries, we assign an F1 score of 0. EQUI-VOCAL performs better than Quivr for different queries and different noise rates.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.2">Results on scene graphs</head><p>Next, we evaluate EQUI-VOCAL on the scene graphs dataset. Neither PATSQL nor Quivr support such flexible queries at video scale. Because the dataset is more complex, EQUI-VOCAL requires that the user provide a slightly larger (although still quite small) number of initial examples to avoid overfitting. We randomly select 15 positive and 15 negative examples from the training set as the initial examples. In the technical report <ref type="bibr">[84]</ref>, we discuss how varying the initial number of examples affects the system performance.</p><p>Figure <ref type="figure">6</ref> shows the F1 score of EQUI-VOCAL under different user labeling budgets. With a larger budget, EQUI-VOCAL can learn queries with higher F1 scores, and achieves a median F1 score of 1.0, 0.91, and 0.67 for easy, medium, and hard queries when the budget is 100. Results for a budget of 50 are nearly identical, which shows that EQUI-VOCAL can synthesize high-quality queries within a reasonable budget, even for complex queries.</p><p>EQUI-VOCAL does not learn good queries in all cases. We note that some queries are easier to synthesize than others, which results in the high variance of the F1 score in Figure <ref type="figure">6</ref>. In particular, EQUI-VOCAL assumes that the ancestor queries of the target query are informative and leverages the performance of those queries to guide the search. However, if the ancestor queries cannot be distinguished from other queries in the same iteration (because they all have the same, typically low, F1 score), EQUI-VOCAL struggles with learning good queries. One direction of future work could explore other  types of more fine-grained user feedback besides binary labels to help EQUI-VOCAL learn intermediate queries <ref type="bibr">[65]</ref>. EQUI-VOCAL's query synthesis time on the scene graphs dataset is greater than on the trajectories dataset. It increases from tens of seconds (Table <ref type="table">5</ref>) to minutes. However, EQUI-VOCAL can easily be parallelized to reduce synthesis time, as executing queries in PostgreSQL is embarrassingly parallel. With eight cores, EQUI-VOCAL achieves a 3.03&#215; speedup and query synthesis time reduces to 13 minutes for the hard, scene-graphs queries with a labeling budget of 50. The query synthesis time can be further reduced by using more cores, further decreasing the labeling budget, decreasing &#119887;&#119908;, or decreasing &#119896;. We show more detailed performance graphs in our technical report <ref type="bibr">[84]</ref>.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.3">Results on real-world dataset</head><p>We compare EQUI-VOCAL and Quivr on the real-world dataset and queries in Table <ref type="table">4</ref>. We randomly select 2 positive and 10 negative examples as initial examples. Since the target events are extremely rare in the dataset, we consider EQUI-VOCAL with two different &#119904; &#119907; values, 100 and 500, to increase the number of sampled positive examples during active learning.</p><p>EQUI-VOCAL outperforms Quivr in terms of F1 scores and query synthesis time on the real-world dataset. Figure <ref type="figure">7</ref> shows the F1 score and query synthesis time of both systems under different labeling budgets. We only show 6 queries due to space constraints, but we include full results in the technical report <ref type="bibr">[84]</ref>. The timeout is set to 4 hours for both systems. EQUI-VOCAL can synthesize all queries in hundreds of seconds with a labeling budget of 30, while Quivr suffers from a low success rate (as shown in Table <ref type="table">7</ref>) and, even when it succeeds, takes thousands of seconds to synthesize queries. EQUI-VOCAL performs poorly with a labeling budget of 12, but with some additional examples, EQUI-VOCAL can easily achieve higher F1 scores. In addition, sampling more candidate segments during active learning (&#119904; &#119907; =500) increases the F1 score in most cases but also slightly increases the synthesis time.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.4">User study</head><p>We conduct a user study to understand the effectiveness and usability of EQUI-VOCAL. We use internal validation since asking</p><p>UQ1 UQ2 UQ3 UQ4 UQ5 UQ6 4 8 12 16 Time (min) Total time System time (a) Task completion time. UQ1 UQ2 UQ3 UQ4 UQ5 UQ6 0.0 0.5 1.0 F1 score Perfect User Simulated Fixed (b) F1 score. participants to provide their own queries would make it difficult to compare across participants. Our goals include observing the system performance in the presence of user noise, measure task completion time, and collect qualitative feedback. We recruited 18 university students studying Computer Science. The study is conducted over the scene graphs dataset with six query tasks with different complexities, as shown in Table <ref type="table">8</ref>.</p><p>We started each session by explaining our definitions of predicates and walking through an example task with participants to get them familiar with the interface and the task. Each participant then completed three query tasks in sequence (either UQ1, 3, 5 or UQ2, 4, 6) with increasing complexity from easy, to medium, to hard. Each query task described the target complex event using natural language. In the user study, we provided the initial examples with ground-truth labels to EQUI-VOCAL so that participants could focus on interacting with the system during query synthesis. We randomly selected 10 positive and 10 negative examples for UQ1, 2 and 4 as the initial examples, and 15 for other queries to account for the increased query complexity. EQUI-VOCAL iteratively selected video segments to label, with a budget of 50 per task. After each task, participants reviewed the synthesized queries and provided subjective ratings and qualitative feedback via a questionnaire.</p><p>Participants are able to complete the task in a reasonable amount of time. Figure <ref type="figure">8a</ref> shows the task completion time of each query. The median completion time of each task ranges between 8.6 and 12.3 minutes. The average time to label a video segment for each query task is 22, 16, 25, 20, 30, and 22 seconds, respectively. Also, the system time only takes a small portion of the total time, suggesting that EQUI-VOCAL is efficient.</p><p>EQUI-VOCAL is resilient to user noise, whereas Quivr is not. Figure <ref type="figure">8b</ref> shows the F1 score of synthesized queries under different labeling scenarios: using the ground-truth labels (Perfect), using real user labels (User), using injected label noise with a false negative rate of 0.3 and a false positive rate of 0.03 (Fixed), and using injected label noise with the same noise rate as users for each query task (Simulated). Each experiment is run nine times. F1 scores of User lie between Perfect and Simulated. Due to the user noise, the query performance decreases compared to using perfect labels. Because the same error rate is used, Simulated's performance is worse or similar to User's, which justifies our expectations for the simulation experiment. For queries that EQUI-VOCAL can synthesize with high quality, participants can help to find them with at least 0.8 F1 scores. Not surprisingly, for queries (UQ5 &amp; 6) that EQUI-VOCAL would fail even with perfect labels, participants cannot instruct the system to achieve better (Near(&#119900; 1 , &#119900; 2 ), Top(&#119900; 3 ), Right(&#119900; 3 ))</p><p>A red object is far from a cylinder, then they get close while a third object is at the top right of the screen.</p><p>12.8% UQ4 (Color(&#119900; 1 , 'purple'), Material(&#119900; 1 , 'metal'), Behind(&#119900; 1 , &#119900; 2 ), Bottom(&#119900; 2 )); Top(&#119900; 2 )</p><p>A purple metal object &#119900; 1 is behind another object &#119900; 2 at the bottom of the screen, then &#119900; 2 moves to the top.</p><p>12.8%</p><p>UQ5 Duration( (Color(&#119900; 1 , 'red'), Shape(&#119900; 2 , 'cylinder'), Far(&#119900; 1 , &#119900; 2 )), 25); (Near(&#119900; 1 , &#119900; 2 ), Top(&#119900; 3 ), Right(&#119900; 3 ))</p><p>A red object is far from a cylinder for at least a second, then they are near each other while a third object is at the top right of the screen.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>4.2%</head><p>UQ6 (Color(&#119900; 1 , 'purple'), Material(&#119900; 1 , 'metal'), Behind(&#119900; 1 , &#119900; 2 ), Bottom(&#119900; 2 )); Top(&#119900; 2 ); Duration( (Bottom(&#119900; 3 ), Right(&#119900; 3 )), 25)</p><p>A purple metal object &#119900; 1 is behind another object &#119900; 2 at the bottom of the screen, then &#119900; 2 moves to the top, then a third object &#119900; 3 is at the bottom right for at least a second. performance using the current prototype. Interestingly, most video segments that EQUI-VOCAL selects for hard queries are negative examples, making it difficult to learn good queries. However, many participants consider some negative samples to be almost positive that fail to satisfy one predicate. This suggests that EQUI-VOCAL could potentially benefit from more fine-grained user feedback.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>3.8%</head><p>Participants would like EQUI-VOCAL to be more responsive. In the questionnaire, the average rating of system responsiveness is 3.53 out of 5. Although the average system time across all tasks is only 195 seconds, participants observe greater latency in early and middle iterations, since there are more branches to expand and more candidate queries to evaluate. Taking UQ1 as an example, the average wait time to receive the first video segment in the 5th iteration is 31 seconds, while in the 10th iteration, it is only 1.3 seconds. Other techniques can be used to further hide the latency of the system <ref type="bibr">[20]</ref>, which is not the focus of this work.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.5">Comparing with machine learning method</head><p>To determine whether a video segment contains an event of interest, EQUI-VOCAL's query synthesis approach could be substituted by training an ML model. However, this approach requires a large number of labeled examples and complicates interpretability <ref type="bibr">[22]</ref>. We compare EQUI-VOCAL against an existing ML approach that builds domain-specific models for videos <ref type="bibr">[20]</ref> on the scene graphs dataset. For EQUI-VOCAL, we adopt the same setting as outlined in Section 5.2, with a labeling budget of 50. The ML approach extracts features using pretrained video and image models and trains a linear model using the same set of user-labeled video segments selected by EQUI-VOCAL. We use both MViT <ref type="bibr">[21]</ref> and CLIP <ref type="bibr">[60]</ref> as the feature extractors. Table <ref type="table">9</ref> shows that EQUI-VOCAL achieves higher F1 scores than the ML approach for all queries, even when using CLIP with all 500 training samples.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6">RELATED WORK</head><p>Video analytics systems. Many recent VDBMSs have been proposed and focus on a wide range of data management challenges, including fast inference over videos <ref type="bibr">[3,</ref><ref type="bibr">5,</ref><ref type="bibr">39,</ref><ref type="bibr">51,</ref><ref type="bibr">55]</ref>, storage optimization <ref type="bibr">[18,</ref><ref type="bibr">27,</ref><ref type="bibr">79]</ref>, efficient dataflow processing <ref type="bibr">[58]</ref>, preprocessing and indexing <ref type="bibr">[6,</ref><ref type="bibr">32,</ref><ref type="bibr">41]</ref>, exploration and organization <ref type="bibr">[19]</ref>, privacy <ref type="bibr">[9]</ref>, and tuning configurations <ref type="bibr">[33,</ref><ref type="bibr">37,</ref><ref type="bibr">63]</ref>. Those techniques are orthogonal to our work.</p><p>Compositional query processing over videos. Several systems have explored compositional queries over videos <ref type="bibr">[7, 11, 14-17, 23, 45, 49, 54, 80]</ref>. However, they either require that users express compositional queries explicitly <ref type="bibr">[14,</ref><ref type="bibr">23,</ref><ref type="bibr">49]</ref>, or train customized models for such events <ref type="bibr">[7,</ref><ref type="bibr">11,</ref><ref type="bibr">17]</ref>. Instead, EQUI-VOCAL uses a query-by-example approach to minimize user effort and learn and refine a query specification iteratively from user feedback.</p><p>Accelerating query execution over visual data. Prior work has focused on accelerating queries by pre-filtering frames to avoid expensive computation <ref type="bibr">[29,</ref><ref type="bibr">30,</ref><ref type="bibr">51]</ref>, optimizing the sampling rate <ref type="bibr">[5,</ref><ref type="bibr">55]</ref>, and building specialized models <ref type="bibr">[3,</ref><ref type="bibr">39]</ref>. EQUI-VOCAL currently extracts all objects in a video before the search process, but could leverage those existing techniques to avoid running expensive object detection and tracking algorithms on all frames.</p><p>Query by example. Many systems have been proposed for SQL queries over relational data <ref type="bibr">[22,</ref><ref type="bibr">48,</ref><ref type="bibr">59,</ref><ref type="bibr">70,</ref><ref type="bibr">73]</ref>. EQUI-VOCAL focuses on learning queries for video events, with a more constrained form than general relational queries. Quivr <ref type="bibr">[54]</ref> is most similar to our work, but it only operates over object trajectories and assumes noiseless inputs.</p><p>Program synthesis. Program synthesis has been used for a wide range of tasks, such as generating referring relational programs <ref type="bibr">[34]</ref>, authoring visualizations <ref type="bibr">[57,</ref><ref type="bibr">74]</ref>, learning relational data transformation <ref type="bibr">[38]</ref>, and synthesizing programs for string processing <ref type="bibr">[56]</ref>. Unlike these systems, EQUI-VOCAL synthesizes queries in the video domain, which is significantly different in terms of the spatio-temporal complexity and the prevalence of noise.</p><p>Active learning. Model Picker <ref type="bibr">[42]</ref> uses active learning to distinguish the best model from a set of pretrained classifiers. EQUI-VOCAL adapts this approach to select the most promising queries to explore. Quivr <ref type="bibr">[54]</ref> also prunes candidate queries using active learning, but only after enumerating all candidates. In contrast, EQUI-VOCAL integrates active learning and labeling into the search process to ensure both synthesis efficiency and query performance.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="7">CONCLUSION</head><p>In this paper, we presented EQUI-VOCAL, a new system that synthesizes compositional queries from examples. EQUI-VOCAL models compositional events as spatio-temporal scene graphs, explores the query search space using results of executing intermediate queries and beam search, leverages active learning to reduce user effort, and generates efficient SQL queries to reduce computational effort.</p></div><note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="1" xml:id="foot_0"><p>In this and the following examples we use English words instead of integers for &#119888;&#119894;&#119889; and &#119901;&#119894;&#119889; values to make the examples more readable</p></note>
		</body>
		</text>
</TEI>
